File Transformation Scopes
TransformFileScope
TransformFileScope// In IMyTargets.cs
[TargetDefinition]
public partial interface IMyTargets : IBuildAccessor
{
Target InjectBuildProperties => t => t
.DescribedAs("Temporarily injects build properties into a project file.")
.Executes(async () =>
{
var projectFile = FileSystem.AtomRootDirectory / "MyProject.csproj";
// Create a scope to add a property
await using (var scope = await TransformFileScope.CreateAsync(projectFile, content =>
{
// Example: Inject a <Version> property
return content.Replace("</Project>", $" <PropertyGroup><Version>1.2.3</Version></PropertyGroup>\n</Project>");
}))
{
Logger.LogInformation("Build properties injected. Performing build...");
await ProcessRunner.RunAsync(new ProcessRunOptions("dotnet", "build", projectFile));
Logger.LogInformation("Build complete. Properties will be restored.");
}
// After 'using' block, MyProject.csproj is restored to its original content
});
}TransformMultiFileScope
TransformMultiFileScopeTransformFileScopeExtensions
TransformFileScopeExtensionsLast updated
Was this helpful?
