【问题标题】:How to create a nuget metapackage with the dotnet command?如何使用 dotnet 命令创建 nuget 元包?
【发布时间】:2020-03-07 09:23:55
【问题描述】:

我有一堆项目的解决方案:

ProjectA.csproj
ProjectB.csproj
ProjectC.csproj

这些都是单独打包为 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

版本号由我们的构建服务器使用 gitversion.exe 自动提取

现在我想制作一个 nuget 元包,它会自动引用所有三个 nupkg。

我可以使用 nuspec 文件来执行此操作,但是当我们的版本号更改时,我需要手动编辑它。

我可以制作第四个项目 ProjectAll.csproj,它引用其他三个项目。但这会让我在使用这些包的应用程序的输出中留下一个空的 DLL。

最好的方法是什么?

【问题讨论】:

    标签: .net .net-core nuget


    【解决方案1】:

    我不知道这是否是一个“秘密”,但对于大多数命令来说,dotnet CLI 只是 msbuild 的一个包装器。这包括 pack,这意味着 NuGet's documentation on the MSBuild pack target 是相关的。如果您向下滚动查看每个标题,或者只是搜索“构建输出”一词,您会找到Output assemblies 部分。上面写着:

    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>
    

    【讨论】:

    • 完美运行!我不知道这个功能。非常感谢。
    猜你喜欢
    • 2022-10-13
    • 1970-01-01
    • 1970-01-01
    • 2017-12-29
    • 1970-01-01
    • 1970-01-01
    • 2019-03-22
    • 2011-10-12
    • 1970-01-01
    相关资源
    最近更新 更多