Skip to content

Commit a4f0170

Browse files
committed
Run the Build target again instead of stripping annotations. Should close #2 and #13.
1 parent 8c499b2 commit a4f0170

File tree

3 files changed

+129
-76
lines changed

3 files changed

+129
-76
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<Project InitialTargets="_ExportAnnotations_CheckPreconditions">
2+
3+
<PropertyGroup>
4+
<MSBuildAllProjects Condition="'$(MSBuildToolsVersion)' != 'Current'">$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
5+
</PropertyGroup>
6+
7+
<!-- Define the appropriate constant to embed annotations into compiled assembly -->
8+
<PropertyGroup>
9+
<DefineConstants Condition="'$(DefineConstants)' != ''">$(DefineConstants);</DefineConstants>
10+
<DefineConstants>$(DefineConstants)JETBRAINS_ANNOTATIONS</DefineConstants>
11+
</PropertyGroup>
12+
13+
<!-- Determine which ExportAnnotations executable to use and how, according to which kind of runtime MSBuild is running in. -->
14+
<PropertyGroup>
15+
16+
<_ExportAnnotationsToolsDirectory>$([System.IO.Path]::GetFullPath($(MSBuildThisFileDirectory)..\tools))\</_ExportAnnotationsToolsDirectory>
17+
18+
<_ExportAnnotationsCommand Condition="'$(MSBuildRuntimeType)' == 'Core'">dotnet </_ExportAnnotationsCommand>
19+
<_ExportAnnotationsCommand Condition="'$(MSBuildRuntimeType)' == 'Full'" />
20+
<_ExportAnnotationsCommand Condition="'$(MSBuildRuntimeType)' == 'Mono'">mono </_ExportAnnotationsCommand>
21+
22+
<_ExportAnnotationsExe Condition="'$(MSBuildRuntimeType)' == 'Core'">$(_ExportAnnotationsToolsDirectory)netcoreapp2.1\ExportAnnotations.dll</_ExportAnnotationsExe>
23+
<_ExportAnnotationsExe Condition="'$(MSBuildRuntimeType)' == 'Full'">$(_ExportAnnotationsToolsDirectory)net471\ExportAnnotations.exe</_ExportAnnotationsExe>
24+
<_ExportAnnotationsExe Condition="'$(MSBuildRuntimeType)' == 'Mono'">$(_ExportAnnotationsToolsDirectory)net471\ExportAnnotations.exe</_ExportAnnotationsExe>
25+
26+
<_ExportAnnotationsCommand>$(_ExportAnnotationsCommand)$(_ExportAnnotationsExe)</_ExportAnnotationsCommand>
27+
28+
</PropertyGroup>
29+
30+
<Target Name="_ExportAnnotations_CheckPreconditions">
31+
32+
<!-- Check for unsupported project type. -->
33+
<Error Condition="'$(MSBuildProjectExtension)' != '.csproj' And '$(MSBuildProjectExtension)' != '.vbproj'"
34+
Text="ReSharper.ExportAnnotations.Task: unsupported project type '$(MSBuildProjectExtension)' (only .csproj and .vbproj are supported)" />
35+
36+
<!-- Check for unsupported MSBuild runtime type. -->
37+
<Error Condition="'$(_ExportAnnotationsCommand)' == ''"
38+
Text="ReSharper.ExportAnnotations.Task: unsupported MSBuild runtime type '$(MSBuildRuntimeType)' (only Core, Full, and Mono are supported)" />
39+
40+
</Target>
41+
42+
<!-- Run tool immediately after compiler -->
43+
<Target Name="_ExportAnnotations_RunTool"
44+
Condition="($(ExportJetBrainsAnnotations) Or $(StripJetBrainsAnnotations)) And ('$(SkipCompilerExecution)' != 'true')"
45+
AfterTargets="CoreCompile">
46+
47+
<PropertyGroup>
48+
<_ExportAnnotationsLibraryList>$(IntermediateOutputPath)ExportAnnotations.libraries</_ExportAnnotationsLibraryList>
49+
</PropertyGroup>
50+
51+
<Message Importance="High" Text="Running ExportAnnotations..." />
52+
53+
<WriteLinesToFile File="$(_ExportAnnotationsLibraryList)"
54+
Lines="@(ReferencePathWithRefAssemblies)"
55+
Overwrite="true" />
56+
57+
<!-- Complete command line with options -->
58+
<PropertyGroup>
59+
<_ExportAnnotationsCommandLine>$(_ExportAnnotationsCommand) &quot;%(IntermediateAssembly.FullPath)&quot;</_ExportAnnotationsCommandLine>
60+
<_ExportAnnotationsCommandLine Condition="!$(ExportJetBrainsAnnotations)">$(_ExportAnnotationsCommandLine) --no-export</_ExportAnnotationsCommandLine>
61+
<_ExportAnnotationsCommandLine>$(_ExportAnnotationsCommandLine) --liblist &quot;$(_ExportAnnotationsLibraryList)&quot;</_ExportAnnotationsCommandLine>
62+
</PropertyGroup>
63+
64+
<!-- Run for every IntermediateAssembly (item fed to Roslyn compilers as output assembly) -->
65+
<Exec Command="$(_ExportAnnotationsCommandLine)" />
66+
67+
</Target>
68+
69+
<!-- Re-run the Build target without JetBrains annotations, only on non-outer, non-design-time builds. -->
70+
<Target Name="_BuildAgainWithoutJetBrainsAnnotations"
71+
Condition="$(StripJetBrainsAnnotations) And '$(TargetFramework)' != '' And '$(DesignTimeBuild)' != 'true'"
72+
AfterTargets="Build">
73+
74+
<Message Importance="High" Text="Rebuilding $(MSBuildProjectFile) without JetBrains annotations..." />
75+
76+
<ItemGroup>
77+
<_FilesToDeleteBeforeRebuildingWithoutJetBrainsAnnotations Include="@(IntermediateAssembly)" />
78+
<_FilesToDeleteBeforeRebuildingWithoutJetBrainsAnnotations Include="@(MainAssembly)" />
79+
</ItemGroup>
80+
81+
<Delete Files="@(_FilesToDeleteBeforeRebuildingWithoutJetBrainsAnnotations)" />
82+
83+
<MSBuild Projects="$(MSBuildProjectFullPath)"
84+
Targets="Build"
85+
Properties="RebuildingWithoutJetBrainsAnnotations=true" />
86+
87+
</Target>
88+
89+
</Project>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<Project>
2+
3+
<PropertyGroup>
4+
<MSBuildAllProjects Condition="'$(MSBuildToolsVersion)' != 'Current'">$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
5+
</PropertyGroup>
6+
7+
<!-- Hook into CopyFilesToOutputDirectory -->
8+
<Target Name="_ExportAnnotations_CopyFilesToOutputDirectory"
9+
Condition="$(ExportJetBrainsAnnotations)"
10+
AfterTargets="CopyFilesToOutputDirectory">
11+
12+
<Copy SourceFiles="@(IntermediateAssembly->'%(RootDir)%(Directory)%(Filename).ExternalAnnotations.xml')"
13+
DestinationFolder="$(OutDir)"
14+
SkipUnchangedFiles="$(SkipCopyUnchangedFiles)"
15+
OverwriteReadOnlyFiles="$(OverwriteReadOnlyFiles)"
16+
Retries="$(CopyRetryCount)"
17+
RetryDelayMilliseconds="$(CopyRetryDelayMilliseconds)"
18+
UseHardlinksIfPossible="$(CreateHardLinksForCopyFilesToOutputDirectoryIfPossible)"
19+
UseSymboliclinksIfPossible="$(CreateSymbolicLinksForCopyFilesToOutputDirectoryIfPossible)"
20+
Condition="'$(CopyBuildOutputToOutputDirectory)' == 'true' and '$(SkipCopyBuildProduct)' != 'true'">
21+
<Output TaskParameter="DestinationFiles" ItemName="FileWrites" />
22+
</Copy>
23+
24+
</Target>
25+
26+
</Project>
Lines changed: 14 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,104 +1,42 @@
1-
<Project InitialTargets="_ExportAnnotations_CheckSupport">
1+
<Project>
22

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

7-
<!-- Build command line according to which kind of runtime MSBuild is running in -->
8-
<PropertyGroup>
9-
10-
<_ExportAnnotationsToolsDirectory>$([System.IO.Path]::GetFullPath($(MSBuildThisFileDirectory)..\tools))\</_ExportAnnotationsToolsDirectory>
11-
12-
<_ExportAnnotationsCommand Condition="'$(MSBuildRuntimeType)' == 'Core'">dotnet </_ExportAnnotationsCommand>
13-
<_ExportAnnotationsCommand Condition="'$(MSBuildRuntimeType)' == 'Full'" />
14-
<_ExportAnnotationsCommand Condition="'$(MSBuildRuntimeType)' == 'Mono'">mono </_ExportAnnotationsCommand>
15-
16-
<_ExportAnnotationsExe Condition="'$(MSBuildRuntimeType)' == 'Core'">$(_ExportAnnotationsToolsDirectory)netcoreapp2.1\ExportAnnotations.dll</_ExportAnnotationsExe>
17-
<_ExportAnnotationsExe Condition="'$(MSBuildRuntimeType)' == 'Full'">$(_ExportAnnotationsToolsDirectory)net471\ExportAnnotations.exe</_ExportAnnotationsExe>
18-
<_ExportAnnotationsExe Condition="'$(MSBuildRuntimeType)' == 'Mono'">$(_ExportAnnotationsToolsDirectory)net471\ExportAnnotations.exe</_ExportAnnotationsExe>
19-
20-
<_ExportAnnotationsCommand>$(_ExportAnnotationsCommand)$(_ExportAnnotationsExe)</_ExportAnnotationsCommand>
21-
22-
</PropertyGroup>
23-
24-
<!-- Issue errors on unsupported project type / MSBuild runtime type -->
25-
<Target Name="_ExportAnnotations_CheckSupport">
26-
<Error Condition="'$(MSBuildProjectExtension)' != '.csproj' And '$(MSBuildProjectExtension)' != '.vbproj'" Text="ReSharper.ExportAnnotations.Task: unsupported project type '$(MSBuildProjectExtension)' (only .csproj and .vbproj are supported)" />
27-
<Error Condition="'$(_ExportAnnotationsCommand)' == ''" Text="ReSharper.ExportAnnotations.Task: unsupported MSBuild runtime type '$(MSBuildRuntimeType)' (only Core, Full, and Mono are supported)" />
28-
</Target>
29-
30-
<!-- Normalize properties related to tool settings -->
7+
<!-- Unless set otherwise, ExportJetBrainsAnnotations is true for libraries, false for other projects. -->
318
<PropertyGroup Condition="'$(ExportJetBrainsAnnotations)' == ''">
329
<ExportJetBrainsAnnotations Condition="'$(OutputType)' != 'Library'">false</ExportJetBrainsAnnotations>
3310
<ExportJetBrainsAnnotations Condition="'$(OutputType)' == 'Library'">true</ExportJetBrainsAnnotations>
3411
</PropertyGroup>
3512
<PropertyGroup>
36-
<StripJetBrainsAnnotations Condition="'$(StripJetBrainsAnnotations)' == ''">true</StripJetBrainsAnnotations>
13+
<ExportJetBrainsAnnotations Condition="'$(ExportJetBrainsAnnotations)' != 'true'">false</ExportJetBrainsAnnotations>
3714
</PropertyGroup>
3815

39-
<!-- Define the appropriate constant to embed annotations into compiled assembly -->
16+
<!-- Unless set otherwise, StripJetBrainsAnnotations is true. -->
4017
<PropertyGroup>
41-
<DefineConstants Condition="'$(DefineConstants)' != ''">$(DefineConstants);</DefineConstants>
42-
<DefineConstants>$(DefineConstants)JETBRAINS_ANNOTATIONS</DefineConstants>
18+
<StripJetBrainsAnnotations Condition="'$(StripJetBrainsAnnotations)' == ''">true</StripJetBrainsAnnotations>
19+
<StripJetBrainsAnnotations Condition="'$(StripJetBrainsAnnotations)' != 'true'">false</StripJetBrainsAnnotations>
4320
</PropertyGroup>
4421

45-
<!-- Run tool immediately after compiler -->
46-
<Target Name="_ExportAnnotations_RunTool"
47-
Condition="($(ExportJetBrainsAnnotations) Or $(StripJetBrainsAnnotations)) And ('$(SkipCompilerExecution)' != 'true')"
48-
AfterTargets="CoreCompile">
49-
50-
<PropertyGroup>
51-
<_ExportAnnotationsLibraryList>$(IntermediateOutputPath)ExportAnnotations.libraries</_ExportAnnotationsLibraryList>
52-
</PropertyGroup>
22+
<Import Condition="'$(RebuildingWithoutJetBrainsAnnotations)' != 'true'"
23+
Project="ReSharper.ExportAnnotations.Task.Building.targets" />
5324

54-
<WriteLinesToFile
55-
File="$(_ExportAnnotationsLibraryList)"
56-
Lines="@(ReferencePathWithRefAssemblies)"
57-
Overwrite="true" />
25+
<Import Condition="'$(RebuildingWithoutJetBrainsAnnotations)' == 'true'"
26+
Project="ReSharper.ExportAnnotations.Task.Rebuilding.targets" />
5827

59-
<!-- Complete command line with options -->
60-
<PropertyGroup>
61-
<_ExportAnnotationsCommandLine>$(_ExportAnnotationsCommand) &quot;%(IntermediateAssembly.FullPath)&quot;</_ExportAnnotationsCommandLine>
62-
<_ExportAnnotationsCommandLine Condition="!$(ExportJetBrainsAnnotations)">$(_ExportAnnotationsCommandLine) --no-export</_ExportAnnotationsCommandLine>
63-
<_ExportAnnotationsCommandLine Condition="$(StripJetBrainsAnnotations)">$(_ExportAnnotationsCommandLine) --strip</_ExportAnnotationsCommandLine>
64-
<_ExportAnnotationsCommandLine>$(_ExportAnnotationsCommandLine) --liblist &quot;$(_ExportAnnotationsLibraryList)&quot;</_ExportAnnotationsCommandLine>
65-
</PropertyGroup>
66-
67-
<!-- Run for every IntermediateAssembly (item fed to Roslyn compilers as output assembly) -->
68-
<Exec Command="$(_ExportAnnotationsCommandLine)" />
69-
70-
</Target>
71-
72-
<!-- Hook into CopyFilesToOutputDirectory -->
73-
<Target Name="_ExportAnnotations_CopyFilesToOutputDirectory"
74-
Condition="$(ExportJetBrainsAnnotations)"
75-
AfterTargets="CopyFilesToOutputDirectory">
76-
77-
<Copy SourceFiles="@(IntermediateAssembly->'%(RootDir)%(Directory)%(Filename).ExternalAnnotations.xml')"
78-
DestinationFolder="$(OutDir)"
79-
SkipUnchangedFiles="$(SkipCopyUnchangedFiles)"
80-
OverwriteReadOnlyFiles="$(OverwriteReadOnlyFiles)"
81-
Retries="$(CopyRetryCount)"
82-
RetryDelayMilliseconds="$(CopyRetryDelayMilliseconds)"
83-
UseHardlinksIfPossible="$(CreateHardLinksForCopyFilesToOutputDirectoryIfPossible)"
84-
UseSymboliclinksIfPossible="$(CreateSymbolicLinksForCopyFilesToOutputDirectoryIfPossible)"
85-
Condition="'$(CopyBuildOutputToOutputDirectory)' == 'true' and '$(SkipCopyBuildProduct)' != 'true'">
86-
<Output TaskParameter="DestinationFiles" ItemName="FileWrites" />
87-
</Copy>
88-
89-
</Target>
90-
91-
<!-- Hook into package creation to add external annotations file to package -->
28+
<!-- Add external annotations file to package -->
9229
<PropertyGroup Condition="$(ExportJetBrainsAnnotations)">
9330
<TargetsForTfmSpecificContentInPackage>$(TargetsForTfmSpecificContentInPackage);_ExportAnnotations_IncludeExternalAnnotationsInPackage</TargetsForTfmSpecificContentInPackage>
9431
</PropertyGroup>
95-
96-
<!-- Add external annotations file to package -->
32+
9733
<Target Name="_ExportAnnotations_IncludeExternalAnnotationsInPackage"
9834
Condition="$(ExportJetBrainsAnnotations)">
35+
9936
<ItemGroup>
10037
<TfmSpecificPackageFile Include="$(OutputPath)\$(AssemblyName).ExternalAnnotations.xml" PackagePath="lib/$(TargetFramework)" />
10138
</ItemGroup>
39+
10240
</Target>
10341

10442
</Project>

0 commit comments

Comments
 (0)