Skip to content

Replace usages of templating mechanism inside msbuild code paths with GenerateFileFromTemplate #53959

@ViktorHofer

Description

@ViktorHofer

With dotnet/arcade#7403 merged, dotnet/runtime can use the GenerateFileFromTemplate task to generate files based on templates from within msbuild. Some code places that would benefit from this:

  • <GenerateRunScript RunCommands="@(RunScriptCommands)"
    TemplatePath="$(RunScriptInputPath)"
    OutputPath="$(RunScriptOutputPath)" />
  • <Target Name="GenerateBatchExecutionScript"
  • <!-- Generate project.csproj from template. -->
    <MakeDir Directories="$(_projectDir)" />
    <WriteLinesToFile
    File="$(_projectFile)"
    Lines="$([System.IO.File]::ReadAllText('$(ProjectTemplate)').Replace('{PackageId}', $(_packageId)).Replace('{PackageVersion}', $(_packageVersion)).Replace('{TargetFrameworks}', $(_projectTFMs)).Replace('{NetCoreAppCurrent}', $(NetCoreAppCurrent)).Replace('{NetCoreAppCurrentVersion}', $(NetCoreAppCurrentVersion)).Replace('{MicrosoftNetCoreAppFrameworkName}', $(MicrosoftNetCoreAppFrameworkName)).Replace('{MicrosoftNetCoreAppRefPackDir}', $(MicrosoftNetCoreAppRefPackDir)).Replace('{RestoreAdditionalProjectSources}', $(ArtifactsPackagesDir)).Replace('{RestorePackagesPath}', $(TestPackageDir)))"
    Overwrite="true" />
  • <MakeDir Directories="$(_projectDir)" />
    <WriteLinesToFile File="$(_projectFile)"
    Lines="$([System.IO.File]::ReadAllText('$(ProjectTemplate)')
    .Replace('{MicrosoftNETCoreAppVersion}', '$(MicrosoftNETCoreAppVersion)')
    .Replace('{NetCoreAppCurrent}', '$(NetCoreAppCurrent)')
    .Replace('{NetCoreAppMaximumVersion}', '$(NetCoreAppMaximumVersion)')
    .Replace('{TargetingPackDir}','$(MicrosoftNetCoreAppRefPackDir)')
    .Replace('{RuntimeIdentifier}','%(TestConsoleApps.TestRuntimeIdentifier)')
    .Replace('{MicrosoftNETILLinkTasksVersion}', '$(MicrosoftNETILLinkTasksVersion)')
    .Replace('{ExtraTrimmerArgs}', '%(TestConsoleApps.ExtraTrimmerArgs)')
    .Replace('{AdditionalProjectReferences}', '$(_additionalProjectReferencesString)')
    .Replace('{RepositoryEngineeringDir}', '$(RepositoryEngineeringDir)')
    .Replace('{MonoAOTCompilerDir}', '$(MonoAOTCompilerDir)')
    .Replace('{MonoProjectRoot}', '$(MonoProjectRoot)')
    .Replace('{MonoAOTCompilerTasksAssemblyPath}', '$(MonoAOTCompilerTasksAssemblyPath)')
    .Replace('{WasmAppBuilderTasksAssemblyPath}', '$(WasmAppBuilderTasksAssemblyPath)')
    .Replace('{MicrosoftNetCoreAppRuntimePackRidDir}', '$(MicrosoftNetCoreAppRuntimePackRidDir)'))"
    Overwrite="true" />

and probably a few others that I that don't know about.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions