[英]how to remove auto generated proto files from generated folder
I have the below MSBuild to generate .cs files from my proto files. 我有以下MSBuild从我的proto文件生成.cs文件。 The build works fine until I do a rebuild where it complains of Source file 'generated-proto-output/Trade.cs# specified multiple times. 构建工作正常,直到我进行重建,它抱怨Source文件'generated-proto-output / Trade.cs#多次指定。
How do I delete my .cs files before building/rebuilding everytime? 如何在每次构建/重建之前删除我的.cs文件?
Error 错误
Severity Code Description Project File Line Suppression State Warning CS2002 Source file 'generated-proto-output\\ErrorTrade.cs' specified multiple times MyComp.Trade.Model C:\\dev\\workspaces\\trade-model-workspace\\model\\csharp\\MyComp.Trade.Model 严重级代码描述项目文件行抑制状态警告CS2002源文件'generated-proto-output \\ ErrorTrade.cs'多次指定MyComp.Trade.Model C:\\ dev \\ workspaces \\ trade-model-workspace \\ model \\ csharp \\ MyComp。 Trade.Model
build snippet in csproj file 在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>
UPDATE - Complete CSProj file (as requested by Lance) 更新 - 完成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>
How do I delete my .cs files before building/rebuilding everytime? 如何在每次构建/重建之前删除我的.cs文件?
Try the following script with BeforeTargets below: 使用下面的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>
In addition: 此外:
Not seeing the whole content of your .csproj, so I can't figure out why the build snippet you use can't work. 没有看到.csproj的全部内容,所以我无法弄清楚为什么你使用的构建片段无法工作。 But a message task may help output some message whether the engine finds the files by your given path. 但是,无论引擎是否通过给定路径找到文件, 消息任务都可以帮助输出一些消息。
In visual studio, if you go Tools=>Options=>Project and Solutions=>Build and Run
to change the build out verbosity to Detailed
, you will see detailed output message after every build and rebuild. 在visual studio中,如果你go Tools=>Options=>Project and Solutions=>Build and Run
将构建详细程度更改为Detailed
,您将在每次构建和重建后看到详细的输出消息。 Ctrl+F
and type the Target name you will find the details about delete process: Ctrl+F
并键入目标名称,您将找到有关删除过程的详细信息:
Hope it makes some help for your trouble-shooting. 希望它能帮助你解决问题。
Try adding CompileOutputs="false"
to the directive. 尝试将CompileOutputs="false"
添加到指令中。 This will suppress the warning and won't require you to delete files before building csharp protobuf build integration 这将禁止警告,并且在构建csharp protobuf构建集成之前不需要您删除文件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.