I created a NETStandard 2.0 project. The tooling support around generating a NuGet package works fine; I can set the Version, Description, etc. What I wanted to do was to extend my project to support a way to generate prerelease versions automatically as well. The solution I came up with was the following modifications to my csproj file:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageId>MyCompany.MyLibrary</PackageId>
<Authors>MyCompany</Authors>
<Version>1.1.8</Version>
</PropertyGroup>
<!-- Support Prerelease Versioning -->
<PropertyGroup Condition="$(IsPrerelease) == true">
<CurrentDate>$([System.DateTime]::Now.ToString(yyyyMMdd-HHmmss))</CurrentDate>
<VersionSuffix>CI-$(CurrentDate)</VersionSuffix>
<Version Condition="'$(Version)' != ''">$(Version)-CI-$(CurrentDate)</Version>
</PropertyGroup>
</Project>
This works fine, specifically because the prerelease PropertyGroup follows the PropertyGroup generated by Visual Studio. If the Version is 1.0.0, Visual Studio removes the property because 1.0.0 is used by default, so the VersionSuffix will work properly. However, if Visual Studio sets the Version (1.1.8), then I need to replace the value of the property (as seen above).
When doing this, msbuild functions appropriately only in the case that no Version is specified:
- msbuild MyCompany.MyLibrary.csproj generates 1.0.0.nupkg
- msbuild MyCompany.MyLibrary.csproj /p:IsPrerelease=true generates 1.0.0-CI-*.nupkg
The next step for me was to pull out the additional PropertyGroup and create a NuGet package: MyCompany.Packaging.Prerelease, which has a .props file. The problem is that if Version is specified, it ignores the fact that I am overwriting that value and even when I specify /p:IsPrerelease=true it generates 1.1.8.nupkg. I'm not sure why, but I have a feeling that I misunderstood the way that NuGet target/props files would be included; I assumed that the NuGet target/props would be appended.
I'm not sure what I can do to alter my MSBuild so that my Prerelease Versioning section is able to overwrite the Version property when pulled in as a NuGet package.