Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Msbuild 如何将特定PackageReference的版本分配给属性_Msbuild - Fatal编程技术网

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

Msbuild 如何将特定PackageReference的版本分配给属性,msbuild,Msbuild,我试图获取通过PackageReference引用的特定软件包的版本,以便我可以引用其中一个软件包中的工具。我能够使用消息任务编写版本: <Message Importance="High" Text="@(PackageReference-&gt;%(PackageReference.Version))" Condition="'%(PackageReference.Identity)' == 'Google.Protobuf.Tools'" /> 如何在属性中检索该

我试图获取通过
PackageReference
引用的特定软件包的版本,以便我可以引用其中一个软件包中的工具。我能够使用
消息
任务编写版本:

<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>

$(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>

全部的
运行时间;建设;本地人;内容文件;分析仪;可传递的