forked from dotnet/roslyn-analyzers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGenerateAnalyzerNuspec.targets
168 lines (142 loc) · 12.1 KB
/
GenerateAnalyzerNuspec.targets
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<!-- Copyright (c) Microsoft. All Rights Reserved. Licensed under the MIT license. See License.txt in the project root for license information. -->
<Project>
<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
</PropertyGroup>
<PropertyGroup>
<NuspecFile>$(IntermediateOutputPath)$(NuspecPackageId).nuspec</NuspecFile>
<NuspecBasePath>$(ArtifactsBinDir)</NuspecBasePath>
<ProduceReferenceAssembly>false</ProduceReferenceAssembly>
<TargetFrameworksForPackage>$(TargetFrameworks)</TargetFrameworksForPackage>
<TargetFrameworksForPackage Condition="'$(TargetFrameworksForPackage)' == ''">$(TargetFramework)</TargetFrameworksForPackage>
</PropertyGroup>
<!--
Projects in this directory do not produce useful binaries, they are only used to generate packages.
-->
<PropertyGroup>
<CopyBuildOutputToOutputDirectory>false</CopyBuildOutputToOutputDirectory>
<CopyOutputSymbolsToOutputDirectory>false</CopyOutputSymbolsToOutputDirectory>
<GenerateDocumentationFile>false</GenerateDocumentationFile>
<PackageLicenseExpression Condition="'$(PackageLicenseExpression)' == ''">MIT</PackageLicenseExpression>
</PropertyGroup>
<PropertyGroup>
<DotNetExecutable Condition="'$(OS)' == 'Windows_NT'">$(DotNetRoot)dotnet.exe</DotNetExecutable>
<DotNetExecutable Condition="'$(DotNetExecutable)' == ''">$(DotNetRoot)dotnet</DotNetExecutable>
<EscapeDirectorySuffix Condition="'$(OS)' == 'Windows_NT'">\</EscapeDirectorySuffix>
</PropertyGroup>
<Target Name="GenerateAnalyzerConfigAndDocumentationFiles"
DependsOnTargets="InitializeSourceControlInformation"
Condition="'@(AnalyzerNupkgAssembly)' != '' or '@(AnalyzerRulesetAssembly)' != ''">
<PropertyGroup>
<_GeneratedRulesetsDir>$(IntermediateOutputPath)Rulesets</_GeneratedRulesetsDir>
<_GeneratedEditorconfigsDir>$(IntermediateOutputPath)Editorconfig</_GeneratedEditorconfigsDir>
<_GeneratedGlobalAnalyzerConfigsDir>$(IntermediateOutputPath)GlobalAnalyzerConfigs</_GeneratedGlobalAnalyzerConfigsDir>
<_ValidateOffline Condition="'$(DotNetBuildSourceOnly)' == 'true' or '$(DotNetBuild)' == 'true'">true</_ValidateOffline>
<_ValidateOffline Condition="'$(_ValidateOffline)' == ''">false</_ValidateOffline>
<ContainsPortedFxCopRules Condition="'$(ContainsPortedFxCopRules)' == ''">false</ContainsPortedFxCopRules>
<GeneratePackagePropsFile Condition="'$(GeneratePackagePropsFile)' == ''">true</GeneratePackagePropsFile>
<GenerateDisableNETAnalyzersPackagePropsFile Condition=" '$(GenerateDisableNETAnalyzersPackagePropsFile)' == '' and '$(ContainsPortedFxCopRules)' == 'true'">true</GenerateDisableNETAnalyzersPackagePropsFile>
<DevelopmentDependency Condition="'@(AnalyzerNupkgAssembly)' != '' or '@(AnalyzerNupkgDependency)' != ''">true</DevelopmentDependency>
<GenerateAnalyzerMdFile Condition="'$(GenerateAnalyzerMdFile)' == ''">true</GenerateAnalyzerMdFile>
<GenerateAnalyzerSarifFile Condition="'$(GenerateAnalyzerSarifFile)' == ''">true</GenerateAnalyzerSarifFile>
<GenerateAnalyzerConfigurationFile Condition="'$(GenerateAnalyzerConfigurationFile)' == ''">true</GenerateAnalyzerConfigurationFile>
</PropertyGroup>
<PropertyGroup Condition="'$(GenerateAnalyzerRulesMissingDocumentationFile)' == ''">
<!-- Generate rules missing documentation file by default for local builds and normal CI builds (to validate the existing files). -->
<GenerateAnalyzerRulesMissingDocumentationFile>true</GenerateAnalyzerRulesMissingDocumentationFile>
<!-- Skip it for internal signed builds that are kicked off after each PR merge builds for improved CI throughput. -->
<GenerateAnalyzerRulesMissingDocumentationFile Condition="'$(Sign)' == 'true'">false</GenerateAnalyzerRulesMissingDocumentationFile>
</PropertyGroup>
<PropertyGroup Condition="'$(ReleaseTrackingOptOut)' == ''">
<ReleaseTrackingOptOut>false</ReleaseTrackingOptOut>
</PropertyGroup>
<PropertyGroup Condition="'$(GeneratePackagePropsFile)' == 'true'">
<PackagePropsFileDir>$(IntermediateOutputPath)Build</PackagePropsFileDir>
<PackagePropsFileName>$(NuspecPackageId).props</PackagePropsFileName>
</PropertyGroup>
<ItemGroup Condition="'$(GeneratePackagePropsFile)' == 'true'" >
<AnalyzerNupkgFile Include="$(PackagePropsFileDir)\$(PackagePropsFileName)"/>
</ItemGroup>
<PropertyGroup Condition="'$(GenerateDisableNETAnalyzersPackagePropsFile)' == 'true'">
<DisableNETAnalyzersPackagePropsFileName>DisableNETAnalyzersForNuGetPackage.props</DisableNETAnalyzersPackagePropsFileName>
</PropertyGroup>
<ItemGroup Condition="'$(GenerateDisableNETAnalyzersPackagePropsFile)' == 'true'" >
<AnalyzerNupkgFile Include="$(PackagePropsFileDir)\$(DisableNETAnalyzersPackagePropsFileName)"/>
</ItemGroup>
<PropertyGroup>
<PackageTargetsFileDir>$(IntermediateOutputPath)Build</PackageTargetsFileDir>
<PackageTargetsFileName>$(NuspecPackageId).targets</PackageTargetsFileName>
</PropertyGroup>
<PropertyGroup Condition="'$(GenerateAnalyzerMdFile)' == 'true'">
<AnalyzerDocumentationFileDir Condition="'$(AnalyzerDocumentationFileDir)' == ''">$(RepoRoot)src\$(NuspecPackageId)</AnalyzerDocumentationFileDir>
<AnalyzerDocumentationFileName>$(NuspecPackageId).md</AnalyzerDocumentationFileName>
</PropertyGroup>
<PropertyGroup Condition="'$(GenerateAnalyzerSarifFile)' == 'true'">
<AnalyzerSarifFileDir Condition="'$(AnalyzerSarifFileDir)' == ''">$(RepoRoot)src\$(NuspecPackageId)</AnalyzerSarifFileDir>
<AnalyzerSarifFileName>$(NuspecPackageId).sarif</AnalyzerSarifFileName>
</PropertyGroup>
<PropertyGroup Condition="'$(GenerateAnalyzerConfigurationFile)' == 'true'">
<AnalyzerConfigurationFileDir>$(RepoRoot)docs</AnalyzerConfigurationFileDir>
<AnalyzerConfigurationFileName>Analyzer Configuration.md</AnalyzerConfigurationFileName>
</PropertyGroup>
<PropertyGroup>
<!--
Source build's runtime environment is incomplete, so we call through a stub project to force assembly resolution
to choose versions from the available subset.
-->
<GenerateDocumentationAndConfigFilesProjectSuffix Condition="'$(DotNetBuildSourceOnly)' == 'true'">ForBrokenRuntime</GenerateDocumentationAndConfigFilesProjectSuffix>
</PropertyGroup>
<MSBuild Projects="$(RepoRoot)src\Tools\GenerateDocumentationAndConfigFiles$(GenerateDocumentationAndConfigFilesProjectSuffix)\GenerateDocumentationAndConfigFiles$(GenerateDocumentationAndConfigFilesProjectSuffix).csproj" Targets="Build">
<Output TaskParameter="TargetOutputs" PropertyName="_GenerateDocumentationAndConfigFilesPath"/>
</MSBuild>
<ItemGroup>
<AnalyzerRulesetAssembly Condition="'@(AnalyzerNupkgAssembly)' != '' and '@(AnalyzerRulesetAssembly)' == ''" Include="@(AnalyzerNupkgAssembly)"/>
<AnalyzerRulesetAssembly Update="@(AnalyzerRulesetAssembly)" Condition="'%(AnalyzerRulesetAssembly.TargetFramework)' == ''" TargetFramework="$(TargetFramework)" />
</ItemGroup>
<!-- Only run validate only in CI builds. Running them in local builds will prevent refreshing auto-generated files. -->
<Exec Condition="'$(ContinuousIntegrationBuild)' == 'true'"
Command='"$(DotNetExecutable)" --roll-forward major "$(_GenerateDocumentationAndConfigFilesPath)" "-validateOnly:true" "$(_GeneratedRulesetsDir)" "$(_GeneratedEditorconfigsDir)" "$(_GeneratedGlobalAnalyzerConfigsDir)" "$(ArtifactsBinDir)$(EscapeDirectorySuffix)" "$(Configuration)" "%(AnalyzerRulesetAssembly.TargetFramework)" "@(AnalyzerRulesetAssembly)" "$(PackagePropsFileDir)" "$(PackagePropsFileName)" "$(PackageTargetsFileDir)" "$(PackageTargetsFileName)" "$(DisableNETAnalyzersPackagePropsFileName)" "$(AnalyzerSarifFileDir)" "$(AnalyzerDocumentationFileName)" "$(AnalyzerSarifFileDir)" "$(AnalyzerSarifFileName)" "$(VersionPrefix)" $(NuspecPackageId) $(ContainsPortedFxCopRules) $(GenerateAnalyzerRulesMissingDocumentationFile) $(ReleaseTrackingOptOut) $(_ValidateOffline)' />
<Exec Command='"$(DotNetExecutable)" --roll-forward major "$(_GenerateDocumentationAndConfigFilesPath)" "-validateOnly:false" "$(_GeneratedRulesetsDir)" "$(_GeneratedEditorconfigsDir)" "$(_GeneratedGlobalAnalyzerConfigsDir)" "$(ArtifactsBinDir)$(EscapeDirectorySuffix)" "$(Configuration)" "%(AnalyzerRulesetAssembly.TargetFramework)" "@(AnalyzerRulesetAssembly)" "$(PackagePropsFileDir)" "$(PackagePropsFileName)" "$(PackageTargetsFileDir)" "$(PackageTargetsFileName)" "$(DisableNETAnalyzersPackagePropsFileName)" "$(AnalyzerSarifFileDir)" "$(AnalyzerDocumentationFileName)" "$(AnalyzerSarifFileDir)" "$(AnalyzerSarifFileName)" "$(VersionPrefix)" $(NuspecPackageId) $(ContainsPortedFxCopRules) $(GenerateAnalyzerRulesMissingDocumentationFile) $(ReleaseTrackingOptOut) $(_ValidateOffline)' />
<ItemGroup Condition="Exists('$(PackageTargetsFileDir)\$(PackageTargetsFileName)')">
<AnalyzerNupkgFile Include="$(PackageTargetsFileDir)\$(PackageTargetsFileName)"/>
</ItemGroup>
</Target>
<PropertyGroup>
<!-- Ideally, we would extract this from the MSBuild task, but we need this as the Target Output before that task is executed -->
<_GenerateAnalyzerNuspecPath>$(ArtifactsBinDir)GenerateAnalyzerNuspec\$(Configuration)\$(NetCurrent)\GenerateAnalyzerNuspec.dll</_GenerateAnalyzerNuspecPath>
</PropertyGroup>
<Target Name="BuildGenerateAnalyzerNuspecFile"
Inputs="$(RepoRoot)src\Tools\GenerateAnalyzerNuspec\Program.cs"
Outputs="$(_GenerateAnalyzerNuspecPath)">
<MSBuild Projects="$(RepoRoot)src\Tools\GenerateAnalyzerNuspec\GenerateAnalyzerNuspec.csproj"
Targets="Restore;Build" >
</MSBuild>
</Target>
<Target Name="GenerateAnalyzerNuspecFile"
BeforeTargets="GenerateNuspec"
DependsOnTargets="InitializeSourceControlInformation;GenerateAnalyzerConfigAndDocumentationFiles;BuildGenerateAnalyzerNuspecFile"
Condition="'@(AnalyzerNupkgFile)' != '' or '@(AnalyzerNupkgFolder)' != '' or '@(AnalyzerNupkgAssembly)' != '' or '@(AnalyzerNupkgDependency)' != '' or '@(AnalyzerNupkgLibrary)' != ''">
<ItemGroup>
<_NuspecMetadata Include="version=$(PackageVersion)" />
<_NuspecMetadata Include="id=$(NuspecPackageId)" />
<_NuspecMetadata Include="authors=$(Authors)" />
<_NuspecMetadata Include="owners=$(Authors)" />
<_NuspecMetadata Include="requireLicenseAcceptance=$(PackageRequireLicenseAcceptance)" />
<_NuspecMetadata Include="description=$(Description)" />
<_NuspecMetadata Include="copyright=$(Copyright)" />
<_NuspecMetadata Include="license=$(PackageLicenseExpression)" />
<_NuspecMetadata Include="projectUrl=$(PackageProjectUrl)" />
<_NuspecMetadata Include="icon=$(PackageIcon)" />
<_NuspecMetadata Include="releaseNotes=$(PackageReleaseNotes)" />
<_NuspecMetadata Include="tags=$(PackageTags)" />
<_NuspecMetadata Include="serviceable=$(Serviceable)" />
<_NuspecMetadata Include="developmentDependency=$(DevelopmentDependency)" />
<_NuspecMetadata Include="repositoryType=$(RepositoryType)" />
<_NuspecMetadata Include="repositoryCommit=$(SourceRevisionId)" />
<_NuspecMetadata Include="repositoryUrl=$(PrivateRepositoryUrl)" />
<_NuspecMetadata Include="readme=$(PackageReadmeFile)" />
</ItemGroup>
<Error Text="Multiple readme files specified for this package." Condition="@(PackageReadmeFileSource->Count()) > 1" />
<Exec Command='"$(DotNetExecutable)" --roll-forward major "$(_GenerateAnalyzerNuspecPath)" "$(NuspecFile)" "$(AssetsDir)$(EscapeDirectorySuffix)" "$(MSBuildProjectDirectory)" "$(Configuration)" "$(TargetFrameworksForPackage)" "@(_NuspecMetadata)" "@(AnalyzerNupkgFile)" "@(PackageReadmeFileSource)" "@(AnalyzerNupkgFolder)" "@(AnalyzerNupkgAssembly)" "@(AnalyzerNupkgDependency)" "@(AnalyzerNupkgLibrary)" "$(_GeneratedRulesetsDir)" "$(_GeneratedEditorconfigsDir)" "$(ArtifactsBinDir)$(EscapeDirectorySuffix)" "$(AnalyzerDocumentationFileDir)" "$(AnalyzerDocumentationFileName)" "$(AnalyzerSarifFileDir)" "$(AnalyzerSarifFileName)" "$(AnalyzerConfigurationFileDir)" "$(AnalyzerConfigurationFileName)" "$(_GeneratedGlobalAnalyzerConfigsDir)"' />
</Target>
</Project>