/
Imports.targets
320 lines (275 loc) · 14.8 KB
/
Imports.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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -->
<Project>
<Import Project="VisualStudio.targets"/>
<Import Project="XUnit.targets" Condition="'$(IsTestProject)' == 'true'" />
<PropertyGroup>
<FileAlignment>512</FileAlignment>
<!--
Only generate our runtimeconfig.json files for net core apps. It's unnecessary in desktop projects
but gets included in lots of output items like VSIX.
-->
<GenerateRuntimeConfigurationFiles Condition="'$(TargetFramework)' != 'netcoreapp1.1' AND '$(TargetFramework)' != 'netcoreapp2.1' AND '$(TargetFramework)' != 'netcoreapp3.0'">false</GenerateRuntimeConfigurationFiles>
<!--
When building a .NET Core exe make sure to include the template runtimeconfig.json file
which has all of our global settings
-->
<UserRuntimeConfig Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' AND '$(OutputType)' == 'Exe'">$(RepositoryEngineeringDir)config\runtimeconfig.template.json</UserRuntimeConfig>
</PropertyGroup>
<ItemGroup Condition="'$(Language)' == 'CSharp' and '$(TargetFramework)' == 'net20'">
<_ExplicitReference Include="$(FrameworkPathOverride)\mscorlib.dll" />
</ItemGroup>
<!--
If the project targets Framework 2.0 reference assemblies provided by Microsoft.NetFramework.ReferenceAssemblies nuget package.
Use the latest Framework toolset to build, but set msbuild properties below
so to avoid 4.5 specific artifacts to be added to the compilation (references, attributes).
-->
<PropertyGroup Condition="'$(TargetFramework)' == 'net20'">
<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
<NoStdLib>true</NoStdLib>
<ResGenExecuteAsTool>false</ResGenExecuteAsTool>
<GenerateResourceMSBuildRuntime>CurrentRuntime</GenerateResourceMSBuildRuntime>
<!-- Bypass a check in msbuild that .NET Framework 3.5 is installed on the machine when targeting .NET < 4.0 -->
<BypassFrameworkInstallChecks>true</BypassFrameworkInstallChecks>
</PropertyGroup>
<!-- Add the UnitTestContainer project capability -->
<ItemGroup Condition="'$(IsTestProject)' == 'true'">
<ProjectCapability Include="UnitTestContainer" />
</ItemGroup>
<!--
Do not copy dependencies to the output directory of a library project, unless it's a unit test project.
-->
<ItemDefinitionGroup Condition="'$(OutputType)' == 'Library' and '$(IsVsixProject)' != 'true' and '$(IsTestProject)' != 'true'">
<Reference>
<Private>False</Private>
</Reference>
<ProjectReference>
<Private>False</Private>
</ProjectReference>
</ItemDefinitionGroup>
<PropertyGroup Condition="'$(ProduceReferenceAssembly)' == '' and (('$(OutputType)' == 'Library' and '$(IsVsixProject)' != 'true' and '$(IsTestProject)' != 'true') or '$(OutputType)' == 'Exe' or '$(OutputType)' == 'WinExe')">
<ProduceReferenceAssembly>true</ProduceReferenceAssembly>
</PropertyGroup>
<!-- Rulesets -->
<PropertyGroup Condition="'$(CodeAnalysisRuleSet)' == ''">
<CodeAnalysisRuleSet Condition="'$(IsShipping)' == 'true'">$(RepositoryEngineeringDir)config\rulesets\Shipping.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRuleSet Condition="'$(IsShipping)' != 'true'">$(RepositoryEngineeringDir)config\rulesets\NonShipping.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<!--
Some dependencies bring in references to UIAutomationClient and UIAutomationTypes. These conflict with the faster
UIAComWrapper implementation used by the Roslyn integration tests. This target sets the alias for the slower
dependencies so they are not used unintentionally within the Roslyn code base.
-->
<Target Name="HideSlowAutomationAssemblies" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences" >
<ItemGroup>
<ReferencePath Condition="'%(FileName)' == 'UIAutomationClient' OR
'%(FileName)' == 'UIAutomationTypes'">
<Aliases>slowautomation</Aliases>
</ReferencePath>
</ItemGroup>
</Target>
<!--
Chain before the .NET Core SDK GetAssemblyAttributes target to add the additional attribute.
-->
<Target Name="_AddCommitHashAttribute"
DependsOnTargets="InitializeSourceControlInformation"
BeforeTargets="GetAssemblyAttributes"
Condition="'$(GenerateMicrosoftCodeAnalysisCommitHashAttribute)' == 'true'">
<ItemGroup>
<AssemblyAttribute Include="Microsoft.CodeAnalysis.CommitHashAttribute">
<_Parameter1 Condition="'$(OfficialBuild)' == 'true'">$(SourceRevisionId)</_Parameter1>
<_Parameter1 Condition="'$(OfficialBuild)' != 'true'"><developer build></_Parameter1>
</AssemblyAttribute>
</ItemGroup>
</Target>
<PropertyGroup>
<TargetFrameworkMonikerAssemblyAttributesPath>$(IntermediateOutputPath)$(TargetFrameworkMoniker).AssemblyAttributes$(DefaultLanguageSourceExtension)</TargetFrameworkMonikerAssemblyAttributesPath>
</PropertyGroup>
<Import Project="Bootstrap.targets" Condition="'$(BootstrapBuildPath)' != ''" />
<!--
When running our determinism tests we need to copy the diagnostic file from the intermediate directory
to the location of the binary. This ensures .dll and .dll.key are next to each other to be picked up
by our test scripts
-->
<Target Name="CopyDeterministicBuildDiagnosticFile" Condition="'$(DebugDeterminism)' != ''" AfterTargets="CoreCompile">
<Copy Condition="'$(IsWpfTempProject)' != 'true' and Exists(@(IntermediateAssembly -> '%(fullpath).key'))"
SourceFiles="@(IntermediateAssembly -> '%(fullpath).key')"
DestinationFolder="$(OutDir)" />
</Target>
<UsingTask TaskName="Microsoft.DotNet.Arcade.Sdk.CompareVersions" AssemblyFile="$(ArcadeSdkBuildTasksAssembly)" />
<UsingTask TaskName="Microsoft.DotNet.Arcade.Sdk.SingleError" AssemblyFile="$(ArcadeSdkBuildTasksAssembly)" />
<Target Name="_CheckRequiredMSBuildVersion" BeforeTargets="BeforeBuild">
<CompareVersions Left="$(MSBuildVersion)" Right="$(MinimumMSBuildVersion)">
<Output TaskParameter="Result" PropertyName="_VersionComparisonResult"/>
</CompareVersions>
<SingleError Text="The msbuild version $(MSBuildVersion) is below the minimum required version $(MinimumMSBuildVersion)"
Condition="$(_VersionComparisonResult) < 0"/>
</Target>
<Target Name="DisableAnalyzers"
BeforeTargets="CoreCompile"
Condition="'$(UseRoslynAnalyzers)' == 'false'">
<!--
Disable analyzers via an MSBuild property settable on the command line.
-->
<ItemGroup>
<Analyzer Remove="@(Analyzer)" />
</ItemGroup>
</Target>
<!--
This target is used to copy referenced projects to a sub-directory vs. the direct output
directory of the build. Useful when the referenced project is an EXE and the referencing
project uses an incompatible TargetFramework (e.g. CommandLineTest -> csc/vbc)
-->
<Target Name="CopyReferencedProjectsToDependenciesDirectory" Condition="'@(RoslynReferenceToDependencyDirectory)' != ''" AfterTargets="ResolveProjectReferences">
<PropertyGroup>
<_RoslynReferenceOutputPath>@(RoslynReferenceToDependencyDirectory->'%(RootDir)%(Directory)')</_RoslynReferenceOutputPath>
</PropertyGroup>
<ItemGroup>
<_RoslynReferenceContent Include="$(_RoslynReferenceOutputPath)*.*" />
<Content Include="@(_RoslynReferenceContent)" Link="dependency\%(_RoslynReferenceContent.Filename)%(_RoslynReferenceContent.Extension)" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
</Target>
<!--
Count PublicAPIs as AdditionalFiles to get them to analyzers. This is working around
https://github.com/dotnet/project-system/issues/2160 where AdditionalFileItemNames
isn't fully supported yet in the new project system. Removal of this hack is tracked
by https://github.com/dotnet/roslyn/issues/19545.
-->
<ItemGroup>
<AdditionalFiles Include="@(PublicAPI)" />
</ItemGroup>
<ItemGroup>
<!-- Show launchSettings.json in the project if it exists. -->
<None Include="$(AppDesignerFolder)\launchSettings.json" Condition="Exists('$(AppDesignerFolder)\launchSettings.json')" />
</ItemGroup>
<!-- CPS doesn't show these items by default, but we want to show them. -->
<ItemGroup>
<!-- XAML pages and resources -->
<None Include="@(Page)" />
<None Include="@(Resource)" />
</ItemGroup>
<!--
Add ThirdPartyNotices.rtf to all shipping NuGet packages.
-->
<ItemGroup Condition="'$(IsPackable)' == 'true' and '$(IsShipping)' == 'true'">
<None Include="$(ThirdPartyNoticesFilePath)" PackagePath="ThirdPartyNotices.rtf" Visible="false" Pack="true"/>
</ItemGroup>
<!--
Append common text to package specific PackageDescription.
-->
<Target Name="_AppendCommonPackageDescription"
BeforeTargets="InitializeStandardNuspecProperties;GenerateNuspec"
DependsOnTargets="InitializeSourceControlInformation"
Condition="'$(IsPackable)' == 'true'">
<PropertyGroup>
<PackageDescription>
$(PackageDescription)
More details at https://aka.ms/roslyn-packages
This package was built from the source at $(PrivateRepositoryUrl)/commit/$(SourceRevisionId).
</PackageDescription>
</PropertyGroup>
</Target>
<!--
Exclude private Visual Studio packages from dependencies of Roslyn packages.
-->
<ItemGroup Condition="'$(IsPackable)' == 'true'">
<PackageReference Update="@(PrivateVisualStudioPackage)" PrivateAssets="all"/>
</ItemGroup>
<!--
Default settings for analyzer packages.
-->
<PropertyGroup Condition="'$(IsPackable)' == 'true' and '$(IsAnalyzer)' == 'true'">
<DevelopmentDependency>true</DevelopmentDependency>
<IncludeBuildOutput>false</IncludeBuildOutput>
<IncludeContentInPack>false</IncludeContentInPack>
</PropertyGroup>
<ItemGroup Condition="'$(IsPackable)' == 'true' and '$(IsAnalyzer)' == 'true'">
<!-- Analyzer packages should not have any dependencies. -->
<PackageReference Update="@(PackageReference)" PrivateAssets="all"/>
<ProjectReference Update="@(ProjectReference)" PrivateAssets="all"/>
<!-- Analyzer packages should contain install scripts. -->
<None Include="$(MSBuildThisFileDirectory)\..\..\src\Setup\PowerShell\install.ps1" PackagePath="tools\install.ps1" Visible="false" Pack="true"/>
<None Include="$(MSBuildThisFileDirectory)\..\..\src\Setup\PowerShell\uninstall.ps1" PackagePath="tools\uninstall.ps1" Visible="false" Pack="true"/>
</ItemGroup>
<!-- RestrictedInternalsVisibleTo -->
<ItemDefinitionGroup>
<RestrictedInternalsVisibleTo>
<Visible>false</Visible>
</RestrictedInternalsVisibleTo>
</ItemDefinitionGroup>
<ItemGroup>
<InternalsVisibleTo Include="@(RestrictedInternalsVisibleTo)" Key="%(Key)" />
</ItemGroup>
<Target Name="PrepareGenerateRestrictedInternalsVisibleTo"
BeforeTargets="PrepareGenerateInternalsVisibleToFile"
Condition="'@(RestrictedInternalsVisibleTo)' != ''">
<ItemGroup>
<_InternalsVisibleToAttribute Include="System.Runtime.CompilerServices.RestrictedInternalsVisibleToAttribute">
<_Parameter1>%(RestrictedInternalsVisibleTo.Identity)</_Parameter1>
<_Parameter2 Condition="'%(RestrictedInternalsVisibleTo.Partner)' != ''">Microsoft.CodeAnalysis.ExternalAccess.%(RestrictedInternalsVisibleTo.Partner).Api</_Parameter2>
</_InternalsVisibleToAttribute>
</ItemGroup>
<Warning Condition="'%(RestrictedInternalsVisibleTo.Partner)' == ''" Text="RestrictedInternalsVisibleTo items must specify the 'Partner' attribute. Target assembly: %(Identity)" />
</Target>
<!--
Ensure TargetFrameworkMonikerAssemblyAttributeText is treated as auto-generated
-->
<Target Name="TreatTargetFrameworkMonikerAssemblyAttributeTextAsGenerated"
AfterTargets="_SetTargetFrameworkMonikerAttribute"
Condition="'$(Language)' == 'VB'">
<PropertyGroup>
<TargetFrameworkMonikerAssemblyAttributeText>
' <autogenerated/>
$(TargetFrameworkMonikerAssemblyAttributeText)
</TargetFrameworkMonikerAssemblyAttributeText>
</PropertyGroup>
</Target>
<Target Name="_CalculateSubstituteVariablesInApplicationManifestInputsOutputs">
<PropertyGroup>
<_OriginalApplicationManifestPath>$(RepositoryEngineeringDir)config\app.manifest</_OriginalApplicationManifestPath>
<_UpdatedApplicationManifestPath>$(IntermediateOutputPath)$(AssemblyName).exe.manifest</_UpdatedApplicationManifestPath>
</PropertyGroup>
</Target>
<!--
Sets the values of "version" and "name" attributes in assemblyIdentity element in the application manifest file
with values $(AssemblyVersion) and $(AssemblyName) to avoid hardcoding those in the manifest file.
-->
<Target Name="_SubstituteVariablesInApplicationManifest"
BeforeTargets="_SetExternalWin32ManifestProperties;_SetEmbeddedWin32ManifestProperties"
DependsOnTargets="_CalculateSubstituteVariablesInApplicationManifestInputsOutputs;GetAssemblyVersion"
Inputs="$(_OriginalApplicationManifestPath)"
Outputs="$(_UpdatedApplicationManifestPath)"
Condition="'$(OutputType)' == 'Exe' And '$(TargetFramework)' == 'net472'">
<Copy SourceFiles="$(_OriginalApplicationManifestPath)" DestinationFiles="$(_UpdatedApplicationManifestPath)" />
<PropertyGroup>
<_Namespace>
<Namespace Prefix="asm" Uri="urn:schemas-microsoft-com:asm.v1" />
</_Namespace>
</PropertyGroup>
<!-- Update version attribute -->
<XmlPoke XmlInputPath="$(_UpdatedApplicationManifestPath)"
Value="$(AssemblyVersion)"
Query="/asm:assembly/asm:assemblyIdentity/@version"
Namespaces="$(_Namespace)"/>
<!-- Update name attribute -->
<XmlPoke XmlInputPath="$(_UpdatedApplicationManifestPath)"
Value="$(AssemblyName)"
Query="/asm:assembly/asm:assemblyIdentity/@name"
Namespaces="$(_Namespace)"/>
<PropertyGroup>
<ApplicationManifest>$(_UpdatedApplicationManifestPath)</ApplicationManifest>
</PropertyGroup>
<ItemGroup>
<FileWrites Include="$(_UpdatedApplicationManifestPath)"/>
</ItemGroup>
</Target>
<!--
Checks assumptions made by TestUsingOptimizedRunner function in build.ps1.
-->
<Target Name="_CheckTestProjectTargetFileName" BeforeTargets="Build" Condition="'$(TargetFramework)' != ''">
<Error Text="Unit test project TargetFileName must end with '.UnitTests.dll': '$(TargetFileName)'"
Condition="$(IsUnitTestProject) != $(TargetFileName.EndsWith('.UnitTests.dll'))" />
<Error Text="Unit test project TargetFileName must end with '.IntegrationTests.dll': '$(TargetFileName)'"
Condition="$(IsIntegrationTestProject) != $(TargetFileName.EndsWith('.IntegrationTests.dll'))" />
</Target>
</Project>