我正在尝试获取通过PackageReference
引用的特定包的版本,以便我可以引用这些包之一中的工具。我可以使用 Message
任务编写版本:
<Message Importance="High" Text="@(PackageReference->%(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/