|
| 1 | +<Project> |
| 2 | + <UsingTask TaskName="ReplaceFileText" TaskFactory="RoslynCodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll"> |
| 3 | + <ParameterGroup> |
| 4 | + <InputFilename ParameterType="System.String" Required="true" /> |
| 5 | + <OutputFilename ParameterType="System.String" Required="true" /> |
| 6 | + <MatchExpression ParameterType="System.String" Required="true" /> |
| 7 | + <ReplacementText ParameterType="System.String" Required="true" /> |
| 8 | + </ParameterGroup> |
| 9 | + <Task> |
| 10 | + <Using Namespace="System" /> |
| 11 | + <Using Namespace="System.IO" /> |
| 12 | + <Using Namespace="System.Text.RegularExpressions" /> |
| 13 | + <Code Type="Fragment" Language="cs"> |
| 14 | + <![CDATA[ |
| 15 | + File.WriteAllText( |
| 16 | + OutputFilename, |
| 17 | + Regex.Replace(File.ReadAllText(InputFilename), MatchExpression, ReplacementText) |
| 18 | + ); |
| 19 | + ]]> |
| 20 | + </Code> |
| 21 | + </Task> |
| 22 | + </UsingTask> |
| 23 | + |
| 24 | + <PropertyGroup> |
| 25 | + <TargetsForTfmSpecificContentInPackage> |
| 26 | + $(TargetsForTfmSpecificContentInPackage); |
| 27 | + SubstituteProfilingInputsMacro; |
| 28 | + </TargetsForTfmSpecificContentInPackage> |
| 29 | + </PropertyGroup> |
| 30 | + |
| 31 | + <Target Name="SubstituteProfilingInputsMacro"> |
| 32 | + <ItemGroup> |
| 33 | + <ProfilingInputsSource Include="ProfilingInputs.props" /> |
| 34 | + <ProfilingInputsTarget Include="$(IntermediateOutputPath)ProfilingInputs.props" /> |
| 35 | + </ItemGroup> |
| 36 | + <ReplaceFileText |
| 37 | + Condition="'$(ProfilingInputsDropName)' != ''" |
| 38 | + InputFilename="@(ProfilingInputsSource)" |
| 39 | + OutputFilename="@(ProfilingInputsTarget)" |
| 40 | + MatchExpression="%TESTSTORE%" |
| 41 | + ReplacementText="vstsdrop:$(ProfilingInputsDropName)" /> |
| 42 | + |
| 43 | + <Warning |
| 44 | + Text="The ProfilingInputsDropName msbuild property has not been set, and the OptProf will not contain accurate content." |
| 45 | + Condition="'$(ProfilingInputsDropName)' == ''" /> |
| 46 | + <Copy SourceFiles="@(ProfilingInputsSource)" DestinationFiles="@(ProfilingInputsTarget)" |
| 47 | + Condition="'$(ProfilingInputsDropName)' == ''" /> |
| 48 | + |
| 49 | + <ItemGroup> |
| 50 | + <TfmSpecificPackageFile Include="@(ProfilingInputsTarget)" PackagePath="InsertionVS/" /> |
| 51 | + </ItemGroup> |
| 52 | + </Target> |
| 53 | + <Target Name="EnsureUniquePackageVersion" |
| 54 | + Condition="'$(Build_BuildId)' != ''" |
| 55 | + AfterTargets="GetBuildVersion"> |
| 56 | + <!-- |
| 57 | + We must ensure unique versions for the insertion metadata package so |
| 58 | + it can contain information that is unique to this build. |
| 59 | + In particular it includes the ProfilingInputsDropName, which contains the BuildId. |
| 60 | + A non-unique package version here may collide with a prior run of this same commit, |
| 61 | + ultimately resulting in a failure of the optprof run. |
| 62 | + --> |
| 63 | + <PropertyGroup> |
| 64 | + <PackageVersion>$(PackageVersion).$(Build_BuildId)</PackageVersion> |
| 65 | + </PropertyGroup> |
| 66 | + </Target> |
| 67 | + <Target Name="BreakForRename" BeforeTargets="Pack;GenerateNuspec" Condition="'$(MSBuildProjectName)'=='Library.VSInsertionMetadata'"> |
| 68 | + <Error Text="This project should be renamed so the library name is used instead of 'Library'. Then delete this target." /> |
| 69 | + </Target> |
| 70 | +</Project> |
0 commit comments