In the .NET project, a pre-build event is configured that generates several source files, it is necessary that these files be included in the project before the build begins. I read here that it is possible in the .csproj file to specify a folder whose contents will be included in the project (and it really works), for example <Content Include="AutoCodegen\**" /> includes all files from the AutoCodegen folder in the project, but this happens only after the project is restarted (for example, restarting the studio). Is there a way to reload the project after the pre-builder or is there any other way to achieve my goal? Thank.

  • Is the number of files dynamic or fixed? - V. Dmitriy
  • one
    You are doing something wrong. Generate files and compile them separately. Or use T4. - VladD
  • In the pre-build event, I use Apache Thrift (it generates source code files based on some description) then these files are used in the project. The number of files is dynamic. - Aleksey
  • @Aleksey you did not answer me. Is the number of files fixed? - V. Dmitriy
  • @ V.Dmitriy replied, "The number of files is dynamic." Apparently in advance to add these files do not work out. not known how many of them. - Murad

1 answer 1

Instead of the pre-build event, you need to use your target in the project file. Inside, you can use the Exec task.

After completing this task, you can replace the list of input files to compile:

 <Target Name="ВашТаргет" BeforeTargets="BeforeCompile"> <Exec ... /> <ItemGroup> <Compile Remove="AutoCodegen\**" /> <Compile Include="AutoCodegen\**" /> </ItemGroup> </Target> 

Such files added dynamically will not be visible in the list of project files - but will be taken into account when compiling.

Restriction. This method is incompatible with R # - it flatly refuses to see the files dynamically added to the project.