Car*_*ing 6 .net nuget .net-core
我有一个包含很多项目的解决方案:
ProjectA.csproj
ProjectB.csproj
ProjectC.csproj
Run Code Online (Sandbox Code Playgroud)
这些都单独打包为 nuget 包:
dotnet pack ProjectA.csproj --version-suffix 1.0.0 ===> ProjectA-1.0.0.nupkg
dotnet pack ProjectB.csproj --version-suffix 1.0.0 ===> ProjectB-1.0.0.nupkg
dotnet pack ProjectC.csproj --version-suffix 1.0.0 ===> ProjectC-1.0.0.nupkg
Run Code Online (Sandbox Code Playgroud)
版本号由我们的构建服务器使用 gitversion.exe 自动提取
现在我想制作一个 nuget 元包,它自动引用所有三个 nupkg。
我可以使用 nuspec 文件来完成此操作,但是当我们的版本号发生变化时,我需要手动编辑它。
我可以创建第四个项目 ProjectAll.csproj,它引用其他三个项目。但这会在使用这些包的应用程序的输出中留下一个空的 DLL。
最好的方法是什么?
我不知道这是否是一个“秘密”,但对于大多数命令来说,dotnet CLI 只是 msbuild 的包装器。这包括 pack,这意味着NuGet 关于 MSBuild pack 目标的文档是相关的。如果您向下滚动查看每个标题,或者只是搜索“构建输出”一词,您将找到“输出程序集”部分。那里说:
IncludeBuildOutput:一个布尔值,用于确定构建输出程序集是否应包含在包中。
因此,在您的项目文件中,您可以包含以下内容:
<Project Sdk="whatever. I can't be bothered looking it up and I haven't memorized it.">
<PropertyGroup>
<TargetFramework>same as your other projects. Most restrictive TFM if different projects have different TFMs</TargetFramework>
<IncludeBuildOutput>false</IncludeBuildOutput>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\path\to\ProjectA.csproj" />
<ProjectReference Include="..\path\to\ProjectB.csproj" />
<ProjectReference Include="..\path\to\ProjectC.csproj" />
<ItemGroup>
</Project>
Run Code Online (Sandbox Code Playgroud)