Click here to Skip to main content
15,887,340 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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>


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)" />
Posted
Updated 26-Mar-19 7:35am
v2

1 solution

Maybe you can use a build automation tool like Cake, see overview here: https://www.slant.co/topics/4014/~make-based-build-automation-tools[^]
 
Share this answer
 
Comments
Member 14197773 27-Mar-19 4:13am    
I actually moved away from cake to MSBuild. I would hope MSBuild supports something like this otherwise I dont see the point in MsBuild being marketed as a build tool. I come from the java world, so its a bit surprising that things arent that easy with csharp.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900