[英]how to remove auto generated proto files from generated folder
我有以下MSBuild从我的proto文件生成.cs文件。 构建工作正常,直到我进行重建,它抱怨Source文件'generated-proto-output / Trade.cs#多次指定。
如何在每次构建/重建之前删除我的.cs文件?
错误
严重级代码描述项目文件行抑制状态警告CS2002源文件'generated-proto-output \\ ErrorTrade.cs'多次指定MyComp.Trade.Model C:\\ dev \\ workspaces \\ trade-model-workspace \\ model \\ csharp \\ MyComp。 Trade.Model
在csproj文件中构建片段
<ItemGroup>
<Protobuf Remove="%(RelativePath)generated-proto-output/**/*.cs" />
<Protobuf Include="../../proto/**/*.proto" ProtoRoot="../../proto/" OutputDir="%(RelativePath)generated-proto-output/" GrpcServices="None" />
<Protobuf Update="../../proto/**/*Service.proto" GrpcServices="Both" />
</ItemGroup>
更新 - 完成CSProj文件(根据Lance的要求)
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<PackageId>TradeStore.Model</PackageId>
<ProtoIncludes>.;../../proto</ProtoIncludes>
<OutputType>Library</OutputType>
<TargetFramework>netstandard2.0</TargetFramework>
<Protobuf_NoWarnMissingExpected>true</Protobuf_NoWarnMissingExpected>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Google.Protobuf" Version="3.6.1" />
<PackageReference Include="Grpc" Version="1.19.0" />
<PackageReference Include="Grpc.Tools" Version="1.19.0" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<FilesToDelete Include="%(RelativePath)generated-proto-output/*.cs" />
</ItemGroup>
<Target Name="DeleteSpecificFiles" BeforeTargets="Build">
<Message Text="Specific Files: @(FilesToDelete)"/>
<Message Text ="Beginning to delete specific files before build or rebuild..."/>
<Delete Files="@(FilesToDelete)"/>
</Target>
<ItemGroup>
<Protobuf Include="../../proto/**/*.proto" ProtoRoot="../../proto/" OutputDir="%(RelativePath)generated-proto-output/" GrpcServices="None" />
<Protobuf Update="../../proto/**/*Service.proto" GrpcServices="Both" />
</ItemGroup>
</Project>
如何在每次构建/重建之前删除我的.cs文件?
使用下面的BeforeTargets尝试以下脚本:
<Project...>
...
<ItemGroup>
<FilesToDelete Include="MyPath/*.cs" />
</ItemGroup>
<Target Name="DeleteSpecificFiles" BeforeTargets="build">
<Message Text="Specific Files: @(FilesToDelete)"/>
<Message Text ="Beginning to delete specific files before build or rebuild..."/>
<Delete Files="@(FilesToDelete)"/>
</Target>
</Project>
此外:
没有看到.csproj的全部内容,所以我无法弄清楚为什么你使用的构建片段无法工作。 但是,无论引擎是否通过给定路径找到文件, 消息任务都可以帮助输出一些消息。
在visual studio中,如果你go Tools=>Options=>Project and Solutions=>Build and Run
将构建详细程度更改为Detailed
,您将在每次构建和重建后看到详细的输出消息。 Ctrl+F
并键入目标名称,您将找到有关删除过程的详细信息:
希望它能帮助你解决问题。
尝试将CompileOutputs="false"
添加到指令中。 这将禁止警告,并且在构建csharp protobuf构建集成之前不需要您删除文件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.