Does anyone know how to modify the csproj file to generate code files during build without actually accessing the files?
A process like:
- create a file
- dynamically reference a temporary file during build
- The compiled assembly has additional elements, depending on the files created during assembly
The purpose of this is to create a way to generate code files using roslyn instead of using t4 templates, which are very inconvenient to use when you try to do something based on attributes.
Therefore, I plan to provide a way to use the special csharp file (for full syntax support) to create files programmatically based on the contents of this special file.
I spent a couple of weeks exploring resources on the Internet (with the msbuild theme), but so far it seems that I have not used the right keywords.
This one was the most insightful for me:
https://www.simple-talk.com/dotnet/.net-tools/extending-msbuild/
My guess is that the correct build target for my goal should be "BeforeCompile" in order to somehow populate the build process with custom code files.
Does anyone have experience working with my problem or know any specific resources related to this task?
Solution: I worked with:
<UsingTask TaskName="DynamicCodeGenerator.DynamicFileGeneratorTask" AssemblyFile="..\DynamicCodeGenerator\bin\Debug\DynamicCodeGenerator.dll" />
<Target Name="DynamicCodeGeneratorTarget" BeforeTargets="BeforeBuild;BeforeRebuild">
<DynamicFileGeneratorTask>
<Output ItemName="Generated" TaskParameter="GeneratedFilePaths" />
</DynamicFileGeneratorTask>
<ItemGroup>
<Compile Include="@(Generated)" />
<FileWrites Include="@(Generated)" />
</ItemGroup>
</Target>
Unfortunately, I did not get it to work with propertygroup overrides, as suggested
Update: this link is also interesting: https://github.com/firstfloorsoftware/xcc/blob/master/FirstFloor.Xcc/Targets/Xcc.targets