1
+ <?xml version =" 1.0" encoding =" utf-8" ?>
2
+ <Project ToolsVersion =" 14.0" xmlns =" http://schemas.microsoft.com/developer/msbuild/2003" >
3
+
4
+ <PropertyGroup >
5
+ <SolutionDir Condition =" $(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'" >$(MSBuildProjectDirectory)\..\</SolutionDir >
6
+
7
+ <!-- Enable the restore command to run before builds -->
8
+ <RestorePackages Condition =" '$(RestorePackages)' == '' " >true</RestorePackages >
9
+
10
+ <!-- Property that enables building a package from a project -->
11
+ <BuildPackage Condition =" '$(BuildPackage)' == '' " >false</BuildPackage >
12
+
13
+ <!-- Determines if package restore consent is required to restore packages -->
14
+ <RequireRestoreConsent Condition =" '$(RequireRestoreConsent)' != 'false' " >false</RequireRestoreConsent >
15
+
16
+ <!-- Download NuGet.exe if it does not already exist -->
17
+ <DownloadNuGetExe Condition =" '$(DownloadNuGetExe)' == '' " >true</DownloadNuGetExe >
18
+ </PropertyGroup >
19
+
20
+ <ItemGroup Condition =" '$(PackageSources)' == '' " >
21
+ <!-- Package sources used to restore packages. -->
22
+ <PackageSource Include =" https://nuget.org/api/v2/" />
23
+ </ItemGroup >
24
+
25
+ <PropertyGroup Condition =" '$(OS)' == 'Windows_NT'" >
26
+ <!-- Windows specific commands -->
27
+ <NuGetToolsPath >$([System.IO.Path]::Combine($(SolutionDir), ".nuget"))</NuGetToolsPath >
28
+ <PackagesConfig >$([System.IO.Path]::Combine($(ProjectDir), "packages.config"))</PackagesConfig >
29
+ </PropertyGroup >
30
+
31
+ <PropertyGroup Condition =" '$(OS)' != 'Windows_NT'" >
32
+ <!-- We need to launch nuget.exe with the mono command if we're not on windows -->
33
+ <NuGetToolsPath >$(SolutionDir).nuget</NuGetToolsPath >
34
+ <PackagesConfig >packages.config</PackagesConfig >
35
+ </PropertyGroup >
36
+
37
+ <PropertyGroup >
38
+ <!-- NuGet command -->
39
+ <NuGetExePath Condition =" '$(NuGetExePath)' == '' " >$(NuGetToolsPath)\nuget.exe</NuGetExePath >
40
+ <PackageSources Condition =" $(PackageSources) == '' " >@(PackageSource)</PackageSources >
41
+
42
+ <NuGetCommand Condition =" '$(OS)' == 'Windows_NT'" >"$(NuGetExePath)"</NuGetCommand >
43
+ <NuGetCommand Condition =" '$(OS)' != 'Windows_NT' " >mono --runtime=v4.0.30319 $(NuGetExePath)</NuGetCommand >
44
+
45
+ <PackageOutputDir Condition =" $(PackageOutputDir) == ''" >$(TargetDir.Trim('\\'))</PackageOutputDir >
46
+
47
+ <RequireConsentSwitch Condition =" $(RequireRestoreConsent) == 'true' " >-RequireConsent</RequireConsentSwitch >
48
+ <!-- Commands -->
49
+ <RestoreCommand >$(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(RequireConsentSwitch) -solutionDir "$(SolutionDir) "</RestoreCommand >
50
+ <BuildCommand >$(NuGetCommand) pack "$(ProjectPath)" -p Configuration=$(Configuration) -o "$(PackageOutputDir)" -symbols</BuildCommand >
51
+
52
+ <!-- We need to ensure packages are restored prior to assembly resolve -->
53
+ <ResolveReferencesDependsOn Condition =" $(RestorePackages) == 'true'" >
54
+ RestorePackages;
55
+ $(ResolveReferencesDependsOn);
56
+ </ResolveReferencesDependsOn >
57
+
58
+ <!-- Make the build depend on restore packages -->
59
+ <BuildDependsOn Condition =" $(BuildPackage) == 'true'" >
60
+ $(BuildDependsOn);
61
+ BuildPackage;
62
+ </BuildDependsOn >
63
+ </PropertyGroup >
64
+
65
+ <Target Name =" CheckPrerequisites" >
66
+ <!-- Raise an error if we're unable to locate nuget.exe -->
67
+ <Error Condition =" '$(DownloadNuGetExe)' != 'true' AND !Exists('$(NuGetExePath)')" Text =" Unable to locate '$(NuGetExePath)'" />
68
+ <SetEnvironmentVariable EnvKey =" VisualStudioVersion" EnvValue =" $(VisualStudioVersion)" Condition =" '$(VisualStudioVersion)' != '' AND '$(OS)' == 'Windows_NT' " />
69
+ <!--
70
+ Take advantage of MsBuild's build dependency tracking to make sure that we only ever download nuget.exe once.
71
+ This effectively acts as a lock that makes sure that the download operation will only happen once and all
72
+ parallel builds will have to wait for it to complete.
73
+ -->
74
+ <MsBuild Targets =" _DownloadNuGet" Projects =" $(MSBuildThisFileFullPath)" Properties =" Configuration=NOT_IMPORTANT" />
75
+ </Target >
76
+
77
+ <Target Name =" _DownloadNuGet" >
78
+ <DownloadNuGet OutputFilename =" $(NuGetExePath)" Condition =" '$(DownloadNuGetExe)' == 'true' AND !Exists('$(NuGetExePath)')" />
79
+ </Target >
80
+
81
+ <Target Name =" RestorePackages" DependsOnTargets =" CheckPrerequisites" >
82
+ <Exec Command =" $(RestoreCommand)"
83
+ Condition =" '$(OS)' != 'Windows_NT' And Exists('$(PackagesConfig)')" />
84
+
85
+ <Exec Command =" $(RestoreCommand)"
86
+ LogStandardErrorAsError =" true"
87
+ Condition =" '$(OS)' == 'Windows_NT' And Exists('$(PackagesConfig)')" />
88
+ </Target >
89
+
90
+ <Target Name =" BuildPackage" DependsOnTargets =" CheckPrerequisites" >
91
+ <Exec Command =" $(BuildCommand)"
92
+ Condition =" '$(OS)' != 'Windows_NT' " />
93
+
94
+ <Exec Command =" $(BuildCommand)"
95
+ LogStandardErrorAsError =" true"
96
+ Condition =" '$(OS)' == 'Windows_NT' " />
97
+ </Target >
98
+
99
+ <UsingTask TaskName =" DownloadNuGet" TaskFactory =" CodeTaskFactory" AssemblyFile =" $(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll" >
100
+ <ParameterGroup >
101
+ <OutputFilename ParameterType =" System.String" Required =" true" />
102
+ </ParameterGroup >
103
+ <Task >
104
+ <Reference Include =" System.Core" />
105
+ <Using Namespace =" System" />
106
+ <Using Namespace =" System.IO" />
107
+ <Using Namespace =" System.Net" />
108
+ <Using Namespace =" Microsoft.Build.Framework" />
109
+ <Using Namespace =" Microsoft.Build.Utilities" />
110
+ <Code Type =" Fragment" Language =" cs" >
111
+ <![CDATA[
112
+ try {
113
+ OutputFilename = Path.GetFullPath(OutputFilename);
114
+
115
+ Log.LogMessage("Downloading latest version of NuGet.exe...");
116
+ WebClient webClient = new WebClient();
117
+ webClient.DownloadFile("https://nuget.org/nuget.exe", OutputFilename);
118
+
119
+ return true;
120
+ }
121
+ catch (Exception ex) {
122
+ Log.LogErrorFromException(ex);
123
+ return false;
124
+ }
125
+ ]]>
126
+ </Code >
127
+ </Task >
128
+ </UsingTask >
129
+
130
+ <UsingTask TaskName =" SetEnvironmentVariable" TaskFactory =" CodeTaskFactory" AssemblyFile =" $(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll" >
131
+ <ParameterGroup >
132
+ <EnvKey ParameterType =" System.String" Required =" true" />
133
+ <EnvValue ParameterType =" System.String" Required =" true" />
134
+ </ParameterGroup >
135
+ <Task >
136
+ <Using Namespace =" System" />
137
+ <Code Type =" Fragment" Language =" cs" >
138
+ <![CDATA[
139
+ try {
140
+ Environment.SetEnvironmentVariable(EnvKey, EnvValue, System.EnvironmentVariableTarget.Process);
141
+ }
142
+ catch {
143
+ }
144
+ ]]>
145
+ </Code >
146
+ </Task >
147
+ </UsingTask >
148
+ </Project >
0 commit comments