VS2017 change netstandard project version via msbu

2019-08-24 12:58发布

问题:

In Visual Studio 2017, there is a new format for netstandard libraries that makes generating nupkg reasonably straight-forward. It looks like this:

In the csproj, it looks like this:

Is there a way of telling msbuild what the package version should be in such away that projects across the sln are updated simultaneously so that the nuspec ends up having the right version dependency? It is probably bug, but when I use msbuild /p:Configuration=Release /p:PackageVersion=3.1.7 and the original hand-typed version is 2.0.0. If I have an alpha and beta project, with beta dependent on alpha, I'll end up with

alpha-3.1.7.nupkg

beta-3.1.7.nupkg dependent on alpha-2.0.0

Perhaps the only way is regex substitution on the csproj, but it would be nice if I could avoid that.

Also, this PackageVersion method does not update the real version:

回答1:

Currently, the versions are locked during restore and not during the build.

As a workaround, you can use

msbuild /restore /p:Version=1.2.3

(Recommended, requires MSBuild 15.5+)

or

msbuild /t:Restore;Pack /p:Version=1.2.3

(Version will also affect the generated assembly version, but you can use PackageVersion to only change the generated nupkg version).

See this GitHub issue for tracking the underlying NuGet issue (currently, the plan is that the dependency versions will be updated during the build in a future release).