microsoft / MSBuildSdks

MSBuild project SDKs
MIT License
459 stars 81 forks source link

Add Artifact file renaming feature #437

Open MatthieuMEZIL opened 1 year ago

MatthieuMEZIL commented 1 year ago

Add Artifact file renaming feature

jeffkl commented 1 year ago

@MatthieuMEZIL can you add some examples in the pull request description on how this will work for end users? I'm having trouble picturing how to convey the intent to have files renamed.

MatthieuMEZIL commented 1 year ago

@jeffkl e.g. <Artifact Include="App.config" RenamedFiles="Foo.exe.config" DestinationFolder="$(O)" />

jeffkl commented 1 year ago

@MatthieuMEZIL a lot of people use wildcards when staging artifacts:

<ItemGroup>
  <Artifact Include="MyFolder\MyStuff"
            FileMatch="*.txt *.ini *.xml"
            DestinationFolder="$(ArtifactsPath)" />
</ItemGroup>

If there's more than file found in the bucket, should there be an error? We don't want to copy all files that match to the same destination file.

I think ideally users could supply a transform but that would be very complicated because we'd have to let the user supply a pattern with tokens and get it right:

<ItemGroup>
  <Artifact Include="MyFolder\MyStuff"
            FileMatch="*.txt *.ini *.xml"
            DestinationFolder="$(ArtifactsPath)"
            DestinationFile="$filename$.altered.$extension$" />
</ItemGroup>

Even then, I think there should be an error or warning if the same file was written to the same path more than once. I'm wondering if its better for the build logic to handle this rename and then have Artifacts just stage the outputs from there after the files are already renamed?