|
| 1 | +<Project> |
| 2 | + <UsingTask TaskName="RenderPublicApiSnapshot" |
| 3 | + TaskFactory="RoslynCodeTaskFactory" |
| 4 | + AssemblyFile="$(MSBuildToolsPath)/Microsoft.Build.Tasks.Core.dll"> |
| 5 | + <ParameterGroup> |
| 6 | + <SourceFile ParameterType="System.String" Required="true" /> |
| 7 | + <OutputFile ParameterType="System.String" Required="true" /> |
| 8 | + <Version ParameterType="System.String" Required="true" /> |
| 9 | + </ParameterGroup> |
| 10 | + <Task> |
| 11 | + <Using Namespace="System.IO" /> |
| 12 | + <Code Type="Fragment" Language="cs"><![CDATA[ |
| 13 | +var directory = Path.GetDirectoryName(OutputFile); |
| 14 | +if (!string.IsNullOrEmpty(directory)) |
| 15 | +{ |
| 16 | + Directory.CreateDirectory(directory); |
| 17 | +} |
| 18 | +
|
| 19 | +var text = File.ReadAllText(SourceFile).Replace("<version>", Version); |
| 20 | +File.WriteAllText(OutputFile, text); |
| 21 | + ]]></Code> |
| 22 | + </Task> |
| 23 | + </UsingTask> |
| 24 | + |
| 25 | + <!-- Render PublicAPI snapshots through a template step so version constants can use <version>. --> |
| 26 | + <Target Name="PreparePublicApiSnapshots" |
| 27 | + BeforeTargets="CoreCompile" |
| 28 | + Condition="Exists('$(MSBuildProjectDirectory)/PublicAPI.Shipped.txt') Or Exists('$(MSBuildProjectDirectory)/PublicAPI.Unshipped.txt')"> |
| 29 | + <PropertyGroup> |
| 30 | + <_PublicApiSnapshotOutputDir>$(IntermediateOutputPath)PublicApiSnapshots/</_PublicApiSnapshotOutputDir> |
| 31 | + </PropertyGroup> |
| 32 | + |
| 33 | + <RenderPublicApiSnapshot SourceFile="$(MSBuildProjectDirectory)/PublicAPI.Shipped.txt" |
| 34 | + OutputFile="$(_PublicApiSnapshotOutputDir)PublicAPI.Shipped.txt" |
| 35 | + Version="$(Version)" |
| 36 | + Condition="Exists('$(MSBuildProjectDirectory)/PublicAPI.Shipped.txt')" /> |
| 37 | + <RenderPublicApiSnapshot SourceFile="$(MSBuildProjectDirectory)/PublicAPI.Unshipped.txt" |
| 38 | + OutputFile="$(_PublicApiSnapshotOutputDir)PublicAPI.Unshipped.txt" |
| 39 | + Version="$(Version)" |
| 40 | + Condition="Exists('$(MSBuildProjectDirectory)/PublicAPI.Unshipped.txt')" /> |
| 41 | + |
| 42 | + <ItemGroup> |
| 43 | + <AdditionalFiles Remove="PublicAPI.Shipped.txt" /> |
| 44 | + <AdditionalFiles Remove="$(MSBuildProjectDirectory)/PublicAPI.Shipped.txt" /> |
| 45 | + <AdditionalFiles Remove="PublicAPI.Unshipped.txt" /> |
| 46 | + <AdditionalFiles Remove="$(MSBuildProjectDirectory)/PublicAPI.Unshipped.txt" /> |
| 47 | + |
| 48 | + <AdditionalFiles Include="$(_PublicApiSnapshotOutputDir)PublicAPI.Shipped.txt" |
| 49 | + Link="PublicAPI.Shipped.txt" |
| 50 | + Condition="Exists('$(MSBuildProjectDirectory)/PublicAPI.Shipped.txt')" /> |
| 51 | + <AdditionalFiles Include="$(_PublicApiSnapshotOutputDir)PublicAPI.Unshipped.txt" |
| 52 | + Link="PublicAPI.Unshipped.txt" |
| 53 | + Condition="Exists('$(MSBuildProjectDirectory)/PublicAPI.Unshipped.txt')" /> |
| 54 | + </ItemGroup> |
| 55 | + </Target> |
| 56 | +</Project> |
0 commit comments