0

I'm working on a project where I generate C# classes in a pre-build step using XSLT and XML to generate those. Those generated classes are included in one file, let's name it "MyClasses.cs" file. The problem now is, if a developer removes the file from the solution after the build is done and try to build the solution again, I see ItemGroup added like that under the project file as follows:

<ItemGroup>
      <Compile Remove="MyClasses.cs" />
    </ItemGroup>

While this won't prevent the generation of the classes again, it causes the solution to not build because the generated classes won't be included in the project. Meaning, the file needs a developer to include manually (right click and include it) so the entire solution can build. So, I wanna do is prevent people to remove the generated code "MyClasses.cs" file so that they can always build or override the behavior of Visual Studio to add an ItemGroup with Remove action for that file when removing it. Is that possible?

Khaled Saleh
  • 116
  • 1
  • 9
  • I agree, this behavior might be confusing, but why do the developers remove the file from the solution in the first place? One should not mess with the project unless one knows what he's doing. – PMF Feb 23 '22 at 07:36
  • It is recommended that you add tags related to Msbuild so that relevant personnel can help you. – Jiale Xue - MSFT Feb 23 '22 at 09:08
  • Thank you JialeXue-MSFT, added. PMF, since it's a generated code, one can think I can delete it and re-generate it again which is actually the initial state when you first clone the solution. – Khaled Saleh Feb 23 '22 at 18:53

0 Answers0