dotnet / dotnet/msbuild

MSBuild should define a mechanism for injecting transformations

Open
#3,128 1 comment 4 reactions 0 assignees View on GitHub
triaged
Dominant language
C#
Stars
5.5k
Forks
1.5k
Avg merge
1d 8h
Merged PRs (30d)
141

Description

We need a stable method for binary re-writing tools to inject themselves to the build process, so that the files built during compilation can be post-processed before being copied to the output directory.

An example for this is the [IL-Linker](https://github.com/mono/linker), which runs ILLinker/Crossgen on MSIL files generated during a build.

The transformations should
* Inject themselves transparently to the rest of the build process (ex: via a package-include)
* Be able to run continuously during a development cycle and preserve incremental compilation.

---

One method of achieving this in ILLinker.targets and other places is to capture the `IntermediateAssembly`, perform the transformation on it, and [rewrite it](https://github.com/mono/linker/blob/39560549290237b27a196672d779519e61c5dd54/corebuild/integration/ILLink.Tasks/ILLink.CrossGen.targets#L36-L42).

This pattern seems one of the better design choices, wrt simplicity and preserving incremental builds. However, the problem with this approach is that certain definitions statically capture the value of `IntermediateAssembly`, thus ignoring downstream modifications. For example:

* https://github.com/Microsoft/msbuild/blob/f72bd2eaa37476819ab7647f63d445df8055dab6/src/Tasks/Microsoft.Common.CurrentVersion.targets#L5472-L5479

* https://github.com/Microsoft/msbuild/blob/f72bd2eaa37476819ab7647f63d445df8055dab6/src/Tasks/Microsoft.Common.CurrentVersion.targets#L391-L393

This will cause other tools that use the pre-captured definitions to behave incorrectly.

One way to mitigate this problem is to maintain the invariant that `IntermediateAssembly` is not captured by any MSBuild definition, and that it is only read/modified within targets.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.