如何从文件夹中删除自动生成的文件 [英] How do I remove auto generated files from a folder

查看:441
本文介绍了如何从文件夹中删除自动生成的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下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文件中的构建片段



I have the below MSBuild to generate .cs files from my proto files. The build works fine until I do a rebuild where it complains of Source file 'generated-proto-output/Trade.cs# specified multiple times.

How do I delete my .cs files before building/rebuilding everytime?

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

build snippet in csproj file

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





我尝试过:



我尝试使用Remove删除* .cs文件但不删除文件。

如何在构建/重建踢开始之前删除文件夹中的文件?



我也试过以下但是没有用



What I have tried:

I tried using Remove to remove the *.cs files but that does not delete the files.
How can I delete files in a folder before the build/rebuild kick starts?

I also tried the below but that did not work

  <ItemGroup>  
     <FilesToDelete Include="%(RelativePath)generated-proto-output/*.*" />
    <Protobuf Include="../../proto/**/*.proto" ProtoRoot="../../proto/" OutputDir="%(RelativePath)generated-proto-output/" GrpcServices="None" />
    <Protobuf Update="../../proto/**/*Service.proto" GrpcServices="Both" />
  </ItemGroup>  
<Delete Files="@(FilesToDelete)" />

推荐答案

也许您可以使用构建自动化工具比如 Cake ,请参阅此处的概述: https:// www .slant.co / topics / 4014 /〜基于make-build-automation-tools [ ^ ]
Maybe you can use a build automation tool like Cake, see overview here: https://www.slant.co/topics/4014/~make-based-build-automation-tools[^]


这篇关于如何从文件夹中删除自动生成的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆