VS2017通过MSBuild更改NetStandard项目版本 [英] VS2017 change netstandard project version via msbuild

查看:508
本文介绍了VS2017通过MSBuild更改NetStandard项目版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Visual Studio 2017中,netstandard库有一种新格式,可以使生成nupkg变得相当简单.看起来像这样:

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

在csproj中,它看起来像这样:

In the csproj, it looks like this:

是否有一种方法可以告诉msbuild软件包的版本,以便同时更新sln上的项目,以便nuspec最终具有正确的版本依赖性?这可能是错误,但是当我使用msbuild /p:Configuration=Release /p:PackageVersion=3.1.7且原始的手工输入版本为2.0.0时.如果我有一个alpha和beta项目,并且beta依赖于alpha,那么我最终会得到

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

alpha-3.1.7.nupkg

beta-3.1.7.nupkg取决于alpha-2.0.0

beta-3.1.7.nupkg dependent on alpha-2.0.0

也许唯一的方法是在csproj上进行正则表达式替换,但是如果可以避免的话,那将是很好的选择.

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

此外,此PackageVersion方法不会更新实际版本:

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

推荐答案

当前,版本在还原过程中而不是在构建过程中被锁定.

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

(推荐,需要MSBuild 15.5 +)

(Recommended, requires MSBuild 15.5+)

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

(Version也会影响生成的程序集版本,但是您可以使用PackageVersion仅更改生成的nupkg版本).

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

请参阅此GitHub问题,以跟踪潜在的NuGet问题(当前为计划是依赖版本会在构建过程中在将来的版本中进行更新.

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).

这篇关于VS2017通过MSBuild更改NetStandard项目版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆