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