【问题标题】:Use nuspec version information from custom target使用来自自定义目标的 nuspec 版本信息
【发布时间】:2020-08-30 22:26:09
【问题描述】:

我正在尝试使用 dotnet CLI 为我们的一种解决方案打包和发布包。我创建了一个目标来执行此操作,以便解决方案中的每个项目都可以使用它。目标如下所示:

<Target Name="PackAndPublishPackages" AfterTargets="AfterBuild" Condition=" '$(Configuration)' == 'Release' And '$(IsDesignTimeBuild)' != 'false' ">
    <PropertyGroup>
        <NuspecFile>$(MSBuildProjectName).nuspec</NuspecFile> 
        <NuspecProperties>Configuration=$(Configuration);Platform=$(Platform)</NuspecProperties>
    </PropertyGroup>

    <Exec Command="del $(MSBuildProjectDirectory)\$(PackageOutputPath)*.nupkg" />
    <Exec Command="dotnet pack $(MSBuildProjectDirectory)\$(MSBuildProjectName).csproj --no-build" />
    <Exec Command="dotnet nuget push $(MSBuildProjectDirectory)\$(PackageOutputPath)*.nupkg -k key -s http://url/" />
</Target>

目标每次都按照我的预期运行,但在运行 dotnet pack 时,它似乎没有使用提供的 nuspec 文件中的版本信息或属性组中定义的列出的 nuspec 属性.我已经确认该文件存在于每个项目的目录中。

【问题讨论】:

    标签: msbuild dotnet-cli nuspec


    【解决方案1】:

    您在目标范围内定义了 PropertyGroup,它仅在目标运行时设置属性。

    您是否尝试将其移出目标?

    <PropertyGroup>
      <NuspecFile>$(MSBuildProjectName).nuspec</NuspecFile> 
      <NuspecProperties>Configuration=$(Configuration);Platform=$(Platform</NuspecProperties>
    </PropertyGroup>
    
    <!-- later in your csproj -->
    
    <Target Name="PackAndPublishPackages" AfterTargets="AfterBuild" Condition=" '$(Configuration)' == 'Release' And '$(IsDesignTimeBuild)' != 'false' ">
      <Exec Command="del $(MSBuildProjectDirectory)\$(PackageOutputPath)*.nupkg" />
      <Exec Command="dotnet pack $(MSBuildProjectDirectory)\$(MSBuildProjectName).csproj --no-build" />
      <Exec Command="dotnet nuget push $(MSBuildProjectDirectory)\$(PackageOutputPath)*.nupkg -k key -s http://url/" />
    </Target>
    

    【讨论】:

    • jpruee,有帮助吗?
    猜你喜欢
    • 2017-10-10
    • 2011-05-17
    • 2013-08-05
    • 2021-12-15
    • 1970-01-01
    • 2018-11-01
    • 2011-11-05
    • 2014-08-31
    • 2012-07-20
    相关资源
    最近更新 更多