[英]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.