Repository navigation
Expand file tree
/
Copy pathDirectory.Build.targets
More file actions
116 lines (105 loc) · 6.41 KB
/
Copy pathDirectory.Build.targets
File metadata and controls
116 lines (105 loc) · 6.41 KB
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
<Project InitialTargets="VerifyProjectSettings">
<!--
It is tempting to place the SDK ref here so that all the projects benefit from it
However, since this repo has C++ VCXPROJ projects, that doesn't work. It will pull
in requirements that break a VCXPROJ (or anything still stuck in the dark ages with Packages.config)
-->
<!--
Since Nuget.config is configured to include the build output location this
will ensure the folder exists during restore so that it won't fail.
-->
<Target Name="CreateBuildOutputNuget" BeforeTargets="Restore;Build;Rebuild">
<MakeDir Directories="$(MSBuildThisFileDirectory)BuildOutput\NuGet" />
</Target>
<!-- Download nuget.exe if it isn't found-->
<Target Name="_DownloadNugetExe" >
<MakeDir Directories="$(PackageOutputPath)" Condition="!EXISTS('$(PackageOutputPath')" />
<DownloadFile Condition="!EXISTS('$(PackageOutputPath)\NuGet.exe')"
SourceUrl="https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
DestinationPath="$(PackageOutputPath)\NuGet.exe"
/>
</Target>
<!--
Version numbers are computed at build time after any declarative properties are evaluated
so this is needed to update the NuSpec properties with the dynamically generated values
NOTE: This can't use NuspecProperties as that is only applicable when using a NuSpec file.
Worse, it can cause a NullReferenceException (See: https://github.com/NuGet/Home/issues/4649 )
-->
<Target Name="_SetNuSpecPropertiesWithBuildInfo"
BeforeTargets="GenerateNuspec"
Condition="'$(MSBuildProjectExtension)'=='.csproj'"
>
<PropertyGroup>
<Description>$(Description) $(llvmVersion)</Description>
</PropertyGroup>
<Message Importance="high" Text="PackageVersion: $(PackageVersion)" />
</Target>
<Target Name="EnsureLocalNugetFolder" Condition="!EXISTS($(PackageOutputPath))" BeforeTargets="Restore">
<MakeDir Directories="$(PackageOutputPath)" />
</Target>
<!-- Custom task to download a file from a web URL -->
<UsingTask TaskName="DownloadFile"
TaskFactory="CodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll"
>
<ParameterGroup>
<SourceUrl ParameterType="System.String" Required="true"/>
<DestinationPath ParameterType="System.String" Required="true"/>
</ParameterGroup>
<Task>
<Using Namespace="System.Net"/>
<Code Type="Fragment" Language="cs">
<![CDATA[
var client = new WebClient();
client.DownloadFile( SourceUrl, DestinationPath );
]]>
</Code>
</Task>
</UsingTask>
<Target Name="EnsureBuildOutputPaths" BeforeTargets="Build;Restore">
<MakeDir Directories="$(PackageOutputPath)"/>
</Target>
<Target Name="ShowBuildParameters" AfterTargets="PrepareVersioningForBuild" Condition="'$(ShowVersioning)'=='true'">
<Message Importance="high" Text="-------------------------------------------"/>
<Message Importance="high" Text=" Project: $(MSBuildProjectFile)" />
<Message Importance="high" Text=" BuildRootDir: $(BuildRootDir)" />
<Message Importance="high" Text=" BaseBuildOutputPath: $(BaseBuildOutputPath)" />
<Message Importance="high" Text=" BaseBuildOutputBinPath: $(BaseBuildOutputBinPath)" />
<Message Importance="high" Text="BaseIntermediateOutputPath: $(BaseIntermediateOutputPath)" />
<Message Importance="high" Text=" IntDir: $(IntDir)" />
<Message Importance="high" Text=" BaseOutputPath: $(BaseOutputPath)" />
<Message Importance="high" Text=" FullBuildNumber: $(FullBuildNumber)"/>
<Message Importance="high" Text=" PackageVersion: $(PackageVersion)"/>
<Message Importance="high" Text=" FileVersion: $(FileVersion)"/>
<Message Importance="high" Text=" LlvmVersion: $(LlvmVersion)"/>
<Message Importance="high" Text=" Platform: $(Platform)"/>
<Message Importance="high" Text=" Configuration: $(Configuration)"/>
<Message Importance="high" Text="-------------------------------------------"/>
</Target>
<Target Name="VerifyProjectSettings" Condition="'$(MSBuildProjectExtension)'=='.csproj'">
<!--
Detect if something has this horrible non-feature `ImplicitUsings` enabled. It is a blight on the build that
should never have been added let alone used as the default for projects with no way to block/disable it all up...
NOTE:
.editorconfig in this repo includes `csharp_style_prefer_top_level_statements = false:error` to ensure that bad
language design choice isn't used either.
NOTE:
While the MSBuild `ImplicitUsings` property is banned from this repo, the C# language feature of global usings is
***NOT***. The `ImplicitUsings` build property will auto include an invisible and undiscoverable (without looking
up obscure documentation) set of namespaces that is NOT consistent or controlled by the developer. THAT is what is
BAD/BROKEN about that feature.
By banning it's use and then providing a `GlobalNamespaceImports.cs` source file with ONLY global using statements
ALL of that is eliminated. Such use of the language feature restores FULL control and visibility of the namespaces
to the developer, where it belongs. For a good explanation of this problem
see: https://rehansaeed.com/the-problem-with-csharp-10-implicit-usings/.
For an explanation of the benefits of the language feature
see: https://www.hanselman.com/blog/implicit-usings-in-net-6
-->
<Error Code="DBT001" Condition="'$(ImplicitUsings)'!='disable'" Text="$(MSBuildProjectFile) - Projects in this repository MUST NOT have ImplicitUsings enabled!"/>
<!--
Until issue https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3902 is resolved directly test for missing file
as this has impacted this repo once already...
-->
<Error Code="DBT002" Condition="!Exists('$(MSBuildThisFileDirectory)stylecop.json')" Text="Missing StyleCop.Json file!"/>
</Target>
</Project>