Skip to content

Commit

Permalink
Run the Build target again instead of stripping annotations. Should c…
Browse files Browse the repository at this point in the history
…lose #2 and #13.
  • Loading branch information
rdeago committed Oct 3, 2020
1 parent 8c499b2 commit a4f0170
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 76 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<Project InitialTargets="_ExportAnnotations_CheckPreconditions">

<PropertyGroup>
<MSBuildAllProjects Condition="'$(MSBuildToolsVersion)' != 'Current'">$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
</PropertyGroup>

<!-- Define the appropriate constant to embed annotations into compiled assembly -->
<PropertyGroup>
<DefineConstants Condition="'$(DefineConstants)' != ''">$(DefineConstants);</DefineConstants>
<DefineConstants>$(DefineConstants)JETBRAINS_ANNOTATIONS</DefineConstants>
</PropertyGroup>

<!-- Determine which ExportAnnotations executable to use and how, according to which kind of runtime MSBuild is running in. -->
<PropertyGroup>

<_ExportAnnotationsToolsDirectory>$([System.IO.Path]::GetFullPath($(MSBuildThisFileDirectory)..\tools))\</_ExportAnnotationsToolsDirectory>

<_ExportAnnotationsCommand Condition="'$(MSBuildRuntimeType)' == 'Core'">dotnet </_ExportAnnotationsCommand>
<_ExportAnnotationsCommand Condition="'$(MSBuildRuntimeType)' == 'Full'" />
<_ExportAnnotationsCommand Condition="'$(MSBuildRuntimeType)' == 'Mono'">mono </_ExportAnnotationsCommand>

<_ExportAnnotationsExe Condition="'$(MSBuildRuntimeType)' == 'Core'">$(_ExportAnnotationsToolsDirectory)netcoreapp2.1\ExportAnnotations.dll</_ExportAnnotationsExe>
<_ExportAnnotationsExe Condition="'$(MSBuildRuntimeType)' == 'Full'">$(_ExportAnnotationsToolsDirectory)net471\ExportAnnotations.exe</_ExportAnnotationsExe>
<_ExportAnnotationsExe Condition="'$(MSBuildRuntimeType)' == 'Mono'">$(_ExportAnnotationsToolsDirectory)net471\ExportAnnotations.exe</_ExportAnnotationsExe>

<_ExportAnnotationsCommand>$(_ExportAnnotationsCommand)$(_ExportAnnotationsExe)</_ExportAnnotationsCommand>

</PropertyGroup>

<Target Name="_ExportAnnotations_CheckPreconditions">

<!-- Check for unsupported project type. -->
<Error Condition="'$(MSBuildProjectExtension)' != '.csproj' And '$(MSBuildProjectExtension)' != '.vbproj'"
Text="ReSharper.ExportAnnotations.Task: unsupported project type '$(MSBuildProjectExtension)' (only .csproj and .vbproj are supported)" />

<!-- Check for unsupported MSBuild runtime type. -->
<Error Condition="'$(_ExportAnnotationsCommand)' == ''"
Text="ReSharper.ExportAnnotations.Task: unsupported MSBuild runtime type '$(MSBuildRuntimeType)' (only Core, Full, and Mono are supported)" />

</Target>

<!-- Run tool immediately after compiler -->
<Target Name="_ExportAnnotations_RunTool"
Condition="($(ExportJetBrainsAnnotations) Or $(StripJetBrainsAnnotations)) And ('$(SkipCompilerExecution)' != 'true')"
AfterTargets="CoreCompile">

<PropertyGroup>
<_ExportAnnotationsLibraryList>$(IntermediateOutputPath)ExportAnnotations.libraries</_ExportAnnotationsLibraryList>
</PropertyGroup>

<Message Importance="High" Text="Running ExportAnnotations..." />

<WriteLinesToFile File="$(_ExportAnnotationsLibraryList)"
Lines="@(ReferencePathWithRefAssemblies)"
Overwrite="true" />

<!-- Complete command line with options -->
<PropertyGroup>
<_ExportAnnotationsCommandLine>$(_ExportAnnotationsCommand) &quot;%(IntermediateAssembly.FullPath)&quot;</_ExportAnnotationsCommandLine>
<_ExportAnnotationsCommandLine Condition="!$(ExportJetBrainsAnnotations)">$(_ExportAnnotationsCommandLine) --no-export</_ExportAnnotationsCommandLine>
<_ExportAnnotationsCommandLine>$(_ExportAnnotationsCommandLine) --liblist &quot;$(_ExportAnnotationsLibraryList)&quot;</_ExportAnnotationsCommandLine>
</PropertyGroup>

<!-- Run for every IntermediateAssembly (item fed to Roslyn compilers as output assembly) -->
<Exec Command="$(_ExportAnnotationsCommandLine)" />

</Target>

<!-- Re-run the Build target without JetBrains annotations, only on non-outer, non-design-time builds. -->
<Target Name="_BuildAgainWithoutJetBrainsAnnotations"
Condition="$(StripJetBrainsAnnotations) And '$(TargetFramework)' != '' And '$(DesignTimeBuild)' != 'true'"
AfterTargets="Build">

<Message Importance="High" Text="Rebuilding $(MSBuildProjectFile) without JetBrains annotations..." />

<ItemGroup>
<_FilesToDeleteBeforeRebuildingWithoutJetBrainsAnnotations Include="@(IntermediateAssembly)" />
<_FilesToDeleteBeforeRebuildingWithoutJetBrainsAnnotations Include="@(MainAssembly)" />
</ItemGroup>

<Delete Files="@(_FilesToDeleteBeforeRebuildingWithoutJetBrainsAnnotations)" />

<MSBuild Projects="$(MSBuildProjectFullPath)"
Targets="Build"
Properties="RebuildingWithoutJetBrainsAnnotations=true" />

</Target>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<Project>

<PropertyGroup>
<MSBuildAllProjects Condition="'$(MSBuildToolsVersion)' != 'Current'">$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
</PropertyGroup>

<!-- Hook into CopyFilesToOutputDirectory -->
<Target Name="_ExportAnnotations_CopyFilesToOutputDirectory"
Condition="$(ExportJetBrainsAnnotations)"
AfterTargets="CopyFilesToOutputDirectory">

<Copy SourceFiles="@(IntermediateAssembly->'%(RootDir)%(Directory)%(Filename).ExternalAnnotations.xml')"
DestinationFolder="$(OutDir)"
SkipUnchangedFiles="$(SkipCopyUnchangedFiles)"
OverwriteReadOnlyFiles="$(OverwriteReadOnlyFiles)"
Retries="$(CopyRetryCount)"
RetryDelayMilliseconds="$(CopyRetryDelayMilliseconds)"
UseHardlinksIfPossible="$(CreateHardLinksForCopyFilesToOutputDirectoryIfPossible)"
UseSymboliclinksIfPossible="$(CreateSymbolicLinksForCopyFilesToOutputDirectoryIfPossible)"
Condition="'$(CopyBuildOutputToOutputDirectory)' == 'true' and '$(SkipCopyBuildProduct)' != 'true'">
<Output TaskParameter="DestinationFiles" ItemName="FileWrites" />
</Copy>

</Target>

</Project>
Original file line number Diff line number Diff line change
@@ -1,104 +1,42 @@
<Project InitialTargets="_ExportAnnotations_CheckSupport">
<Project>

<PropertyGroup>
<MSBuildAllProjects Condition="'$(MSBuildToolsVersion)' != 'Current'">$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
</PropertyGroup>

<!-- Build command line according to which kind of runtime MSBuild is running in -->
<PropertyGroup>

<_ExportAnnotationsToolsDirectory>$([System.IO.Path]::GetFullPath($(MSBuildThisFileDirectory)..\tools))\</_ExportAnnotationsToolsDirectory>

<_ExportAnnotationsCommand Condition="'$(MSBuildRuntimeType)' == 'Core'">dotnet </_ExportAnnotationsCommand>
<_ExportAnnotationsCommand Condition="'$(MSBuildRuntimeType)' == 'Full'" />
<_ExportAnnotationsCommand Condition="'$(MSBuildRuntimeType)' == 'Mono'">mono </_ExportAnnotationsCommand>

<_ExportAnnotationsExe Condition="'$(MSBuildRuntimeType)' == 'Core'">$(_ExportAnnotationsToolsDirectory)netcoreapp2.1\ExportAnnotations.dll</_ExportAnnotationsExe>
<_ExportAnnotationsExe Condition="'$(MSBuildRuntimeType)' == 'Full'">$(_ExportAnnotationsToolsDirectory)net471\ExportAnnotations.exe</_ExportAnnotationsExe>
<_ExportAnnotationsExe Condition="'$(MSBuildRuntimeType)' == 'Mono'">$(_ExportAnnotationsToolsDirectory)net471\ExportAnnotations.exe</_ExportAnnotationsExe>

<_ExportAnnotationsCommand>$(_ExportAnnotationsCommand)$(_ExportAnnotationsExe)</_ExportAnnotationsCommand>

</PropertyGroup>

<!-- Issue errors on unsupported project type / MSBuild runtime type -->
<Target Name="_ExportAnnotations_CheckSupport">
<Error Condition="'$(MSBuildProjectExtension)' != '.csproj' And '$(MSBuildProjectExtension)' != '.vbproj'" Text="ReSharper.ExportAnnotations.Task: unsupported project type '$(MSBuildProjectExtension)' (only .csproj and .vbproj are supported)" />
<Error Condition="'$(_ExportAnnotationsCommand)' == ''" Text="ReSharper.ExportAnnotations.Task: unsupported MSBuild runtime type '$(MSBuildRuntimeType)' (only Core, Full, and Mono are supported)" />
</Target>

<!-- Normalize properties related to tool settings -->
<!-- Unless set otherwise, ExportJetBrainsAnnotations is true for libraries, false for other projects. -->
<PropertyGroup Condition="'$(ExportJetBrainsAnnotations)' == ''">
<ExportJetBrainsAnnotations Condition="'$(OutputType)' != 'Library'">false</ExportJetBrainsAnnotations>
<ExportJetBrainsAnnotations Condition="'$(OutputType)' == 'Library'">true</ExportJetBrainsAnnotations>
</PropertyGroup>
<PropertyGroup>
<StripJetBrainsAnnotations Condition="'$(StripJetBrainsAnnotations)' == ''">true</StripJetBrainsAnnotations>
<ExportJetBrainsAnnotations Condition="'$(ExportJetBrainsAnnotations)' != 'true'">false</ExportJetBrainsAnnotations>
</PropertyGroup>

<!-- Define the appropriate constant to embed annotations into compiled assembly -->
<!-- Unless set otherwise, StripJetBrainsAnnotations is true. -->
<PropertyGroup>
<DefineConstants Condition="'$(DefineConstants)' != ''">$(DefineConstants);</DefineConstants>
<DefineConstants>$(DefineConstants)JETBRAINS_ANNOTATIONS</DefineConstants>
<StripJetBrainsAnnotations Condition="'$(StripJetBrainsAnnotations)' == ''">true</StripJetBrainsAnnotations>
<StripJetBrainsAnnotations Condition="'$(StripJetBrainsAnnotations)' != 'true'">false</StripJetBrainsAnnotations>
</PropertyGroup>

<!-- Run tool immediately after compiler -->
<Target Name="_ExportAnnotations_RunTool"
Condition="($(ExportJetBrainsAnnotations) Or $(StripJetBrainsAnnotations)) And ('$(SkipCompilerExecution)' != 'true')"
AfterTargets="CoreCompile">

<PropertyGroup>
<_ExportAnnotationsLibraryList>$(IntermediateOutputPath)ExportAnnotations.libraries</_ExportAnnotationsLibraryList>
</PropertyGroup>
<Import Condition="'$(RebuildingWithoutJetBrainsAnnotations)' != 'true'"
Project="ReSharper.ExportAnnotations.Task.Building.targets" />

<WriteLinesToFile
File="$(_ExportAnnotationsLibraryList)"
Lines="@(ReferencePathWithRefAssemblies)"
Overwrite="true" />
<Import Condition="'$(RebuildingWithoutJetBrainsAnnotations)' == 'true'"
Project="ReSharper.ExportAnnotations.Task.Rebuilding.targets" />

<!-- Complete command line with options -->
<PropertyGroup>
<_ExportAnnotationsCommandLine>$(_ExportAnnotationsCommand) &quot;%(IntermediateAssembly.FullPath)&quot;</_ExportAnnotationsCommandLine>
<_ExportAnnotationsCommandLine Condition="!$(ExportJetBrainsAnnotations)">$(_ExportAnnotationsCommandLine) --no-export</_ExportAnnotationsCommandLine>
<_ExportAnnotationsCommandLine Condition="$(StripJetBrainsAnnotations)">$(_ExportAnnotationsCommandLine) --strip</_ExportAnnotationsCommandLine>
<_ExportAnnotationsCommandLine>$(_ExportAnnotationsCommandLine) --liblist &quot;$(_ExportAnnotationsLibraryList)&quot;</_ExportAnnotationsCommandLine>
</PropertyGroup>

<!-- Run for every IntermediateAssembly (item fed to Roslyn compilers as output assembly) -->
<Exec Command="$(_ExportAnnotationsCommandLine)" />

</Target>

<!-- Hook into CopyFilesToOutputDirectory -->
<Target Name="_ExportAnnotations_CopyFilesToOutputDirectory"
Condition="$(ExportJetBrainsAnnotations)"
AfterTargets="CopyFilesToOutputDirectory">

<Copy SourceFiles="@(IntermediateAssembly->'%(RootDir)%(Directory)%(Filename).ExternalAnnotations.xml')"
DestinationFolder="$(OutDir)"
SkipUnchangedFiles="$(SkipCopyUnchangedFiles)"
OverwriteReadOnlyFiles="$(OverwriteReadOnlyFiles)"
Retries="$(CopyRetryCount)"
RetryDelayMilliseconds="$(CopyRetryDelayMilliseconds)"
UseHardlinksIfPossible="$(CreateHardLinksForCopyFilesToOutputDirectoryIfPossible)"
UseSymboliclinksIfPossible="$(CreateSymbolicLinksForCopyFilesToOutputDirectoryIfPossible)"
Condition="'$(CopyBuildOutputToOutputDirectory)' == 'true' and '$(SkipCopyBuildProduct)' != 'true'">
<Output TaskParameter="DestinationFiles" ItemName="FileWrites" />
</Copy>

</Target>

<!-- Hook into package creation to add external annotations file to package -->
<!-- Add external annotations file to package -->
<PropertyGroup Condition="$(ExportJetBrainsAnnotations)">
<TargetsForTfmSpecificContentInPackage>$(TargetsForTfmSpecificContentInPackage);_ExportAnnotations_IncludeExternalAnnotationsInPackage</TargetsForTfmSpecificContentInPackage>
</PropertyGroup>

<!-- Add external annotations file to package -->

<Target Name="_ExportAnnotations_IncludeExternalAnnotationsInPackage"
Condition="$(ExportJetBrainsAnnotations)">

<ItemGroup>
<TfmSpecificPackageFile Include="$(OutputPath)\$(AssemblyName).ExternalAnnotations.xml" PackagePath="lib/$(TargetFramework)" />
</ItemGroup>

</Target>

</Project>

0 comments on commit a4f0170

Please sign in to comment.