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
@@ -49,6 +49,25 @@ Files generated during execution don't exist during the evaluation phase, theref
49
49
50
50
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).
51
51
52
+
If you put the above into a file and call it `buildcodegen.targets`, you can run `dotnet new console`, import the file, and then build it to test everything:
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
+
64
+
</Project>
65
+
```
66
+
67
+
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`:
68
+
69
+
`ildasm CodeGen.dll`
70
+
52
71
## Next steps
53
72
54
73
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