msbuild - 如何将特定 PackageReference 的版本分配给属性

标签 msbuild

我正在尝试获取通过PackageReference引用的特定包的版本,以便我可以引用这些包之一中的工具。我可以使用 Message 任务编写版本:

<Message Importance="High" Text="@(PackageReference-&gt;%(PackageReference.Version))" Condition="'%(PackageReference.Identity)' == 'Google.Protobuf.Tools'" />

如何检索属性内的该值?

我的 csproj 中的相关部分如下所示:

<ItemGroup>
  <PackageReference Include="Google.Protobuf" Version="3.5.0" />
  <PackageReference Include="Google.Protobuf.Tools" Version="3.5.0" />
  <PackageReference Include="Grpc" Version="1.8.0" />
  <PackageReference Include="Grpc.Tools" Version="1.8.0" />
</ItemGroup>

<PropertyGroup>
  <ProtobufCompiler>$(UserProfile)/.nuget/packages/Google.Protobuf.Tools/3.5.0/tools/windows_x64/protoc.exe</ProtobufCompiler>
  <GrpcCSharpPlugin>$(UserProfile)/.nuget/packages/Grpc.Tools/1.8.0/tools/windows_x64/grpc_csharp_plugin.exe</GrpcCSharpPlugin>
</PropertyGroup>

最佳答案

我发现我可以使用 CreateProperty 任务来实现:

<CreateProperty Value="%(PackageReference.Version)" Condition="%(PackageReference.Identity) == 'Google.Protobuf.Tools'">
  <Output TaskParameter="Value" PropertyName="GoogleProtobufToolsVersion" />
</CreateProperty>

关于msbuild - 如何将特定 PackageReference 的版本分配给属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50945793/

相关文章:

tfs - 有没有更好的方法来查看团队构建日志?

visual-studio - 如何将app.config放到app.config下面?

.net - 如何在 Visual Studio 中通过 F5 部署加载项库?

grails - 将gant构建脚本转换为ant脚本

c# - 如何在 .csproj 的 StartProgram 设置中指定命令行参数?

.net - msbuild/clickonce 发布构建期间生成的文件

msbuild - 如何为 msbuild 构建的 C++ 项目设置输出目录?

.net - NuGet 自动包还原不适用于 MSBuild

c# - 无法从传输连接读取数据 : An existing connection was forcibly closed by the remote host

build - 将构建日志创建到特定项目文件夹中,同时从 Cmd 控制台使用 MSbuild 编译 .sln 文件