我想设置一个包含构建、测试和部署阶段的 CI/CD 管道。
我可以在构建阶段构建我的项目
msbuild src\MyProject.csproj /t:Restore
msbuild src\MyProject.csproj /p:Configuration=Release /p:OutputPath=../BuildOutput
接下来我将构建并运行测试..\BuildOutput\MyProject.dll
那已经建成了。
msbuild tests\MyProject.Tests.csproj /t:Restore
msbuild tests\MyProject.Tests.csproj /p:Configuration=Release /p:OutputPath=../BuildOutput /p:BuildProjectReferences=false
vstest.console BuildOutput\MyProject.Tests.dll
到目前为止,它似乎有效。
现在我想生成nuget包。
我可以打电话:
msbuild src\MyProject.csproj /t:Pack /p:Configuration=Release /p:OutputPath=../BuildOutput /p:VersionPrefix=1.2.3
这将创造MyProject.1.2.3.nupkg
in BuildOutput
文件夹。
然而它重新构建了该项目。
我正在寻找类似的东西dotnet
cli.
dotnet pack --no-build
但我不能使用dotnet
因为我的项目有 COM 引用。
我还查看了 Nuget.exe,但当我调用时它似乎抛出错误nuget pack
Unable to cast object of type 'System.String' to type NuGet.Frameworks.NuGet.Frameworks1051960.NuGetFramework'.
msbuild有一个可以跳过构建的属性吗?
这取决于您的工作流程中是否可以接受,但您可以使用<GeneratePackageOnBuild>
财产在一个<PropertyGroup>
你的.csproj
文件以在构建项目时获取包。如果您的测试没有通过,您可以放弃.nupkg
文件,但至少没有额外的重建来获取 NuGet 包。
There is a more complete example of how to use this setting at the end of the article Easily supporting multiple target frameworks (TFMs) with VS2017 and Nuget1, but an exemplary very simple snippet would look like this:
<PropertyGroup>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
</PropertyGroup>
1: While the original link does not report a 404, it appears as blank in October 2021. The same article can, however, be found on another URL.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)