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)' == '' Or '$(OS)' != 'Windows_NT' " >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 >
29+ <!-- We need to launch nuget.exe with the mono command if we're not on windows -->
30+ <NuGetToolsPath >$(SolutionDir).nuget</NuGetToolsPath >
31+ <PackagesConfig >packages.config</PackagesConfig >
32+ </PropertyGroup >
33+
34+ <PropertyGroup >
35+ <!-- NuGet command -->
36+ <NuGetExePath Condition =" '$(NuGetExePath)' == '' " >$(NuGetToolsPath)\NuGet.exe</NuGetExePath >
37+ <PackageSources Condition =" $(PackageSources) == '' " >@(PackageSource)</PackageSources >
38+
39+ <NuGetCommand Condition =" '$(OS)' == 'Windows_NT'" >"$(NuGetExePath)"</NuGetCommand >
40+ <NuGetCommand Condition =" '$(OS)' != 'Windows_NT' " >mono --runtime=v4.0.30319 $(NuGetExePath)</NuGetCommand >
41+
42+ <PackageOutputDir Condition =" $(PackageOutputDir) == ''" >$(TargetDir.Trim('\\'))</PackageOutputDir >
43+
44+ <RequireConsentSwitch Condition =" $(RequireRestoreConsent) == 'true' " >-RequireConsent</RequireConsentSwitch >
45+ <!-- Commands -->
46+ <RestoreCommand >$(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(RequireConsentSwitch) -solutionDir "$(SolutionDir) "</RestoreCommand >
47+ <BuildCommand >$(NuGetCommand) pack "$(ProjectPath)" -p Configuration=$(Configuration) -o "$(PackageOutputDir)" -symbols</BuildCommand >
48+
49+ <!-- We need to ensure packages are restored prior to assembly resolve -->
50+ <BuildDependsOn Condition =" $(RestorePackages) == 'true'" >
51+ RestorePackages;
52+ $(BuildDependsOn);
53+ </BuildDependsOn >
54+
55+ <!-- Make the build depend on restore packages -->
56+ <BuildDependsOn Condition =" $(BuildPackage) == 'true'" >
57+ $(BuildDependsOn);
58+ BuildPackage;
59+ </BuildDependsOn >
60+ </PropertyGroup >
61+
62+ <Target Name =" CheckPrerequisites" >
63+ <!-- Raise an error if we're unable to locate nuget.exe -->
64+ <Error Condition =" '$(DownloadNuGetExe)' != 'true' AND !Exists('$(NuGetExePath)')" Text =" Unable to locate '$(NuGetExePath)'" />
65+ <SetEnvironmentVariable EnvKey =" VisualStudioVersion" EnvValue =" $(VisualStudioVersion)" Condition =" '$(VisualStudioVersion)' != '' AND '$(OS)' == 'Windows_NT' " />
66+ <!--
67+ Take advantage of MsBuild's build dependency tracking to make sure that we only ever download nuget.exe once.
68+ This effectively acts as a lock that makes sure that the download operation will only happen once and all
69+ parallel builds will have to wait for it to complete.
70+ -->
71+ <MsBuild Targets =" _DownloadNuGet" Projects =" $(MSBuildThisFileFullPath)" Properties =" Configuration=NOT_IMPORTANT" />
72+ </Target >
73+
74+ <Target Name =" _DownloadNuGet" >
75+ <DownloadNuGet OutputFilename =" $(NuGetExePath)" Condition =" '$(DownloadNuGetExe)' == 'true' AND !Exists('$(NuGetExePath)')" />
76+ </Target >
77+
78+ <Target Name =" RestorePackages" DependsOnTargets =" CheckPrerequisites" >
79+ <Exec Command =" $(RestoreCommand)" Condition =" Exists('$(PackagesConfig)')" />
80+ </Target >
81+
82+ <Target Name =" BuildPackage" DependsOnTargets =" CheckPrerequisites" >
83+ <Exec Command =" $(BuildCommand)" />
84+ </Target >
85+
86+ <UsingTask TaskName =" DownloadNuGet" TaskFactory =" CodeTaskFactory" AssemblyFile =" $(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll" >
87+ <ParameterGroup >
88+ <OutputFilename ParameterType =" System.String" Required =" true" />
89+ </ParameterGroup >
90+ <Task >
91+ <Reference Include =" System.Core" />
92+ <Using Namespace =" System" />
93+ <Using Namespace =" System.IO" />
94+ <Using Namespace =" System.Net" />
95+ <Using Namespace =" Microsoft.Build.Framework" />
96+ <Using Namespace =" Microsoft.Build.Utilities" />
97+ <Code Type =" Fragment" Language =" cs" >
98+ <![CDATA[
99+ try {
100+ OutputFilename = Path.GetFullPath(OutputFilename);
101+
102+ Log.LogMessage("Downloading latest version of NuGet.exe...");
103+ WebClient webClient = new WebClient();
104+ webClient.DownloadFile("https://nuget.org/nuget.exe", OutputFilename);
105+
106+ return true;
107+ }
108+ catch (Exception ex) {
109+ Log.LogErrorFromException(ex);
110+ return false;
111+ }
112+ ]]>
113+ </Code >
114+ </Task >
115+ </UsingTask >
116+
117+ <UsingTask TaskName =" SetEnvironmentVariable" TaskFactory =" CodeTaskFactory" AssemblyFile =" $(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll" >
118+ <ParameterGroup >
119+ <EnvKey ParameterType =" System.String" Required =" true" />
120+ <EnvValue ParameterType =" System.String" Required =" true" />
121+ </ParameterGroup >
122+ <Task >
123+ <Using Namespace =" System" />
124+ <Code Type =" Fragment" Language =" cs" >
125+ <![CDATA[
126+ try {
127+ Environment.SetEnvironmentVariable(EnvKey, EnvValue, System.EnvironmentVariableTarget.Process);
128+ }
129+ catch {
130+ }
131+ ]]>
132+ </Code >
133+ </Task >
134+ </UsingTask >
135+ </Project >
0 commit comments