Skip to content

Added support for variable replacement in transformed files#318

Open
gthvidsten wants to merge 1 commit into
microsoft:mainfrom
gthvidsten:main
Open

Added support for variable replacement in transformed files#318
gthvidsten wants to merge 1 commit into
microsoft:mainfrom
gthvidsten:main

Conversation

@gthvidsten
Copy link
Copy Markdown

Rationale

For a solution with many projects, where each project can have multiple .config files, and each .config file can have several transforms (one per developer) it can quickly become very hard to maintain.

Using "variable replacement" the transform files can be changed to have only one file for the developer environments.
Each developer can then create a Directory.Build.targets at the root of the solution, and having this file in .gitignore so that the developers don't overwrite each others changes.
Alternatively there can be a common Directory.Build.targets that imports another target file where the imported file is ignored in git.

An example of Directory.Build.targets can be found in the WebApplication and ConsoleApp, but the gist of it is:

<Project>
  <ItemGroup>
    <ScReplaceToken Include="VariableKey" Value="VariableValue" />
  </ItemGroup>
</Project>

The advantage of this is that MSBuild properties can be expanded into this <ItemGroup>, while they cannot be expanded into a Task.

The transform file can then include $(VariableKey) which will be replaced with VariableValue during the transform.

@gthvidsten
Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

@gthvidsten
Copy link
Copy Markdown
Author

@ttstanley Any comments or questions? Would be nice to have this :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant