I have multiple CodeCoverage.xml files in seperate directories and I want to copy them to a single directory with new names so that they don't get overwritten.
<ItemGroup>
<CoverageResultsXmlFiles Include="$(TestResultsDir)\**\CodeCoverage.xml" />
</ItemGroup>
Do开发者_Python百科es anyone have an idea of how to copy these files to the $(TestResultsDir) without them being overwritten?
Is there a way to generate a random number that could be pre-pended to the filename so they would be unique?
You can do it with MSBuild 4.0 features:
<Target Name="CopyCodeCoverage">
<PropertyGroup>
<DirIdentity>$(RecursiveDir.Replace(" ", "_"))</DirIdentity>
<DirIdentity>$(DirIdentity.Replace("\", "_"))</DirIdentity>
<UniqueIdentity>$([System.IO.Path]::GetRandomFileName())</UniqueIdentity>
<DestCodeCoverage>$(DestinationDir)\$(DirIdentity)_$(UniqueIdentity)_CodeCoverage.xml</DestCodeCoverage>
</PropertyGroup>
<Copy SourceFiles="$(CodeCoverageFullPath)"
DestinationFiles="$(DestCodeCoverage)"
SkipUnchangedFiles="true" />
</Target>
<Target Name="ProcessResults">
<MSBuild Projects="$(MSBuildProjectFullPath)"
Targets="CopyCodeCoverage"
Properties="CodeCoverageFullPath=%(CoverageResultsXmlFiles.FullPath);RecursiveDir=%(CoverageResultsXmlFiles.RecursiveDir);DestinationDir=$(TestResultsDir)" />
</Target>
@Sayed Ibrahim Hashimi has excellent post about property functions and using static .Net methods. So you can implement any naming algorithm you want.
精彩评论