Msbuild 如何将特定PackageReference的版本分配给属性
我试图获取通过Msbuild 如何将特定PackageReference的版本分配给属性,msbuild,Msbuild,我试图获取通过PackageReference引用的特定软件包的版本,以便我可以引用其中一个软件包中的工具。我能够使用消息任务编写版本: <Message Importance="High" Text="@(PackageReference->%(PackageReference.Version))" Condition="'%(PackageReference.Identity)' == 'Google.Protobuf.Tools'" /> 如何在属性中检索该
PackageReference
引用的特定软件包的版本,以便我可以引用其中一个软件包中的工具。我能够使用消息
任务编写版本:
<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>
$(UserProfile)/.nuget/packages/Google.Protobuf.Tools/3.5.0/Tools/windows_x64/protoc.exe
$(UserProfile)/.nuget/packages/Grpc.Tools/1.8.0/Tools/windows_x64/Grpc_csharp_plugin.exe
我发现我可以使用CreateProperty
任务:
<CreateProperty Value="%(PackageReference.Version)" Condition="%(PackageReference.Identity) == 'Google.Protobuf.Tools'">
<Output TaskParameter="Value" PropertyName="GoogleProtobufToolsVersion" />
</CreateProperty>
最新的Grps.Tools在构建过程中调用proto编译器
<ItemGroup>
<PackageReference Include="Grpc.Tools" Version="2.31.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<Protobuf Include="my.proto" GrpcServices="None">
</Protobuf>
全部的
运行时间;建设;本地人;内容文件;分析仪;可传递的