简体   繁体   English

如何从生成的文件夹中删除自动生成的原型文件

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

相关问题 Visual Studio 从 gRPC.proto 文件自动生成代码 - Visual Studio auto generated code from gRPC .proto file 从SonarLint分析中删除自动生成的代码 - Remove Auto-generated Code from SonarLint Analysis 如何获取VC#来重建自动生成的.cs文件? - How to get VC# to rebuild auto-generated .cs files? 如何防止在单元测试结果“out”文件夹中生成pdb文件? - How to prevent pdb files from being generated in unit test results “out” folder? 如何添加//<auto-generated /> 自动生成文件? 更具体的迁移 - How to add //<auto-generated /> automatically to generated files? More specifically migrations 如何增加自动生成的 ID - How to increment the Auto Generated Id 如何以及在何处修改DataAdapter中自动生成的查询? - How and where can I modify the auto generated query from DataAdapter? ElasticSearch-如何从插入查询中获取自动生成的ID - ElasticSearch - how to get the auto generated id from an insert query 将XML注释重新插入自动生成的[assembly] .xml文件中的C#源文件树中 - Reinserting XML Comments into a tree of C# source files from the auto generated [assembly].xml files 如何从openapi 2.0生成的对象命名空间中删除破折号 - How to remove dashes from object namespace, generated by openapi 2.0
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM