【问题标题】:How to create a nuget file with both the Release and Debug configurations using msbuild in Azure Devops如何在 Azure Devops 中使用 msbuild 创建具有发布和调试配置的 nuget 文件
【发布时间】:2020-02-03 21:59:27
【问题描述】:

我需要创建一个 nuget 文件,其中包含我的 dll 的发布版本和调试版本。我需要能够使用 MSBuild 任务在 Azure Devops 中执行此操作。

由于 NuGet 任务中的错误,我正在使用 MSBuild,如果您使用新的包引用和项目引用,它不会正确执行依赖项信息。

我尝试过进行两次构建,一次在调试中,一次在发布中,然后让发布版本进行打包。这仍然只给了我一个文件。我还尝试使用 nuspec 文件来告诉它抓取两个文件,但这仍然只导致包中的一个文件。

【问题讨论】:

    标签: azure-devops msbuild nuget-package


    【解决方案1】:

    如何在 Azure Devops 中使用 msbuild 创建具有发布和调试配置的 nuget 文件

    恐怕您目前无法创建使用 msbuild 的 Release 和 Debug 配置的 nuget 文件。

    这是因为 NuGet 包通常只包含一组特定目标框架的程序集。它并不是真正为发布调试和发布版本而设计的。

    如果我们使用 nuget,我们可以使用 .nuspec 中的自定义 MSBuild .targets 文件,该文件有自己的引用和配置信息:

    查看this thread了解更多详情。

    但是,如果要使用MSBuild,我们无法直接指定dll文件,我们必须为debugrelease创建两个包,然后我们在项目文件中添加一个自定义的MSBuild .targets文件具有<Pack>true</Pack><PackagePath>build\</PackagePath> 属性,如下所示:

      <ItemGroup>
        <None Include="build\*.targets" Pack="True" PackagePath="build\" />
      </ItemGroup>
    

    这种情况下,.targets文件会被打包到build文件夹中,然后导入到nuget安装工程中:

    查看this thread了解更多详情。

    此外,在.targets 文件中,您可以使用Choose/Whendebugrelease 选择PackageReference

    <Choose>
        <When Condition=" '$(Configuration)'=='debug' ">
            <ItemGroup>
                <PackageReference Include="MyRefDebug"> 
                  <Version>1.0</Version> 
                </PackageReference>
            </ItemGroup>
        </When>
        <Otherwise>
            <ItemGroup>
                <PackageReference Include="MyRefRelease"> 
                  <Version>2.0</Version> 
                </PackageReference>
            </ItemGroup>
        </Otherwise>
    </Choose>
    

    查看github ticket 了解更多详情。

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-10-07
      • 2019-03-26
      • 2020-09-14
      • 2019-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多