You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adding your generated file to `None` or `Content` is sufficient for the build process to see it. You also want to ensure it gets added at the right time. Ideally, your target runs before `BeforeBuild`. `AssignTargetPaths` is another possible target, as it is the final opportunity to modify `None` and `Content` items (among others) before they are transformed into new items. See [Common Item Types](common-msbuild-project-items.md).
40
51
52
+
Copy the above, paste it into a file, and call it `buildcodegen.targets`. Then, run `dotnet new console`, import the file, and build it to see how it works.
53
+
54
+
```xml
55
+
<ProjectSdk="Microsoft.NET.Sdk">
56
+
<ImportProject="buildcodegen.targets"/>
57
+
<PropertyGroup>
58
+
<OutputType>Exe</OutputType>
59
+
<TargetFramework>net9.0</TargetFramework>
60
+
<ImplicitUsings>enable</ImplicitUsings>
61
+
<Nullable>enable</Nullable>
62
+
</PropertyGroup>
63
+
</Project>
64
+
```
65
+
66
+
Run *msbuild.exe* and look at the output to verify that your file was generated and copied to the output folder. You can use *ildasm.exe* to confirm that your output binaries include the generated code `MyEnum`:
67
+
68
+
`ildasm CodeGen.dll`
69
+
70
+
## Next steps
71
+
72
+
This example could be improved to support more realistic use cases. For example, to support [incremental builds](./incremental-builds.md) when the generated code depends on an input file, `Inputs` and `Outputs` should be provided to the target. Such a target would only regenerate the file if the date of the input file or files is more recent than the output file. Often when customizing for code generation, it's recommended to create a custom task. See [Create a custom task for code generation](./tutorial-custom-task-code-generation.md).
0 commit comments