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)' == '' " >true</RestorePackages >
8
+
9
+ <!-- Property that enables building a package from a project -->
10
+ <BuildPackage Condition =" '$(BuildPackage)' == '' " >false</BuildPackage >
11
+
12
+ <!-- Download NuGet.exe if it does not already exist -->
13
+ <DownloadNuGetExe Condition =" '$(DownloadNuGetExe)' == '' " >true</DownloadNuGetExe >
14
+ </PropertyGroup >
15
+
16
+ <ItemGroup Condition =" '$(PackageSources)' == '' " >
17
+ <!-- Package sources used to restore packages. By default will used the registered sources under %APPDATA%\NuGet\NuGet.Config -->
18
+ <!--
19
+ <PackageSource Include="https://nuget.org/api/v2/" />
20
+ <PackageSource Include="https://my-nuget-source/nuget/" />
21
+ -->
22
+ </ItemGroup >
23
+
24
+ <PropertyGroup Condition =" '$(OS)' == 'Windows_NT'" >
25
+ <!-- Windows specific commands -->
26
+ <NuGetToolsPath >$([System.IO.Path]::Combine($(SolutionDir), ".nuget"))</NuGetToolsPath >
27
+ <PackagesConfig >$([System.IO.Path]::Combine($(ProjectDir), "packages.config"))</PackagesConfig >
28
+ <PackagesDir >$([System.IO.Path]::Combine($(SolutionDir), "packages"))</PackagesDir >
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
+ <PackagesDir >$(SolutionDir)packages</PackagesDir >
36
+ </PropertyGroup >
37
+
38
+ <PropertyGroup >
39
+ <!-- NuGet command -->
40
+ <NuGetExePath Condition =" '$(NuGetExePath)' == '' " >$(NuGetToolsPath)\nuget.exe</NuGetExePath >
41
+ <PackageSources Condition =" $(PackageSources) == '' " >@(PackageSource)</PackageSources >
42
+
43
+ <NuGetCommand Condition =" '$(OS)' == 'Windows_NT'" >"$(NuGetExePath)"</NuGetCommand >
44
+ <NuGetCommand Condition =" '$(OS)' != 'Windows_NT' " >mono --runtime=v4.0.30319 $(NuGetExePath)</NuGetCommand >
45
+
46
+ <PackageOutputDir Condition =" $(PackageOutputDir) == ''" >$(TargetDir.Trim('\\'))</PackageOutputDir >
47
+
48
+ <!-- Commands -->
49
+ <RestoreCommand >$(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" -o "$(PackagesDir)"</RestoreCommand >
50
+ <BuildCommand >$(NuGetCommand) pack "$(ProjectPath)" -p Configuration=$(Configuration) -o "$(PackageOutputDir)" -symbols</BuildCommand >
51
+
52
+ <!-- Make the build depend on restore packages -->
53
+ <BuildDependsOn Condition =" $(RestorePackages) == 'true'" >
54
+ RestorePackages;
55
+ $(BuildDependsOn);
56
+ </BuildDependsOn >
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
+ <DownloadNuGet OutputFilename =" $(NuGetExePath)" Condition =" '$(DownloadNuGetExe)' == 'true' AND !Exists('$(NuGetExePath)')" />
70
+ </Target >
71
+
72
+ <Target Name =" RestorePackages" DependsOnTargets =" CheckPrerequisites" >
73
+ <Exec Command =" $(RestoreCommand)"
74
+ Condition =" '$(OS)' != 'Windows_NT' And Exists('$(PackagesConfig)')" />
75
+
76
+ <Exec Command =" $(RestoreCommand)"
77
+ LogStandardErrorAsError =" true"
78
+ Condition =" '$(OS)' == 'Windows_NT' And Exists('$(PackagesConfig)')" />
79
+ </Target >
80
+
81
+ <Target Name =" BuildPackage" DependsOnTargets =" CheckPrerequisites" >
82
+ <Exec Command =" $(BuildCommand)"
83
+ Condition =" '$(OS)' != 'Windows_NT' " />
84
+
85
+ <Exec Command =" $(BuildCommand)"
86
+ LogStandardErrorAsError =" true"
87
+ Condition =" '$(OS)' == 'Windows_NT' " />
88
+ </Target >
89
+
90
+ <UsingTask TaskName =" DownloadNuGet" TaskFactory =" CodeTaskFactory" AssemblyFile =" $(MSBuildToolsPath)\Microsoft.Build.Tasks.v$(MSBuildToolsVersion).dll" >
91
+ <ParameterGroup >
92
+ <OutputFilename ParameterType =" System.String" Required =" true" />
93
+ </ParameterGroup >
94
+ <Task >
95
+ <Reference Include =" System.Core" />
96
+ <Using Namespace =" System" />
97
+ <Using Namespace =" System.IO" />
98
+ <Using Namespace =" System.Net" />
99
+ <Using Namespace =" Microsoft.Build.Framework" />
100
+ <Using Namespace =" Microsoft.Build.Utilities" />
101
+ <Code Type =" Fragment" Language =" cs" >
102
+ <![CDATA[
103
+ try {
104
+ OutputFilename = Path.GetFullPath(OutputFilename);
105
+
106
+ Log.LogMessage("Downloading latest version of NuGet.exe...");
107
+ WebClient webClient = new WebClient();
108
+ webClient.DownloadFile("https://nuget.org/nuget.exe", OutputFilename);
109
+
110
+ return true;
111
+ }
112
+ catch (Exception ex) {
113
+ Log.LogErrorFromException(ex);
114
+ return false;
115
+ }
116
+ ]]>
117
+ </Code >
118
+ </Task >
119
+ </UsingTask >
120
+
121
+ <UsingTask TaskName =" SetEnvironmentVariable" TaskFactory =" CodeTaskFactory" AssemblyFile =" $(MSBuildToolsPath)\Microsoft.Build.Tasks.v$(MSBuildToolsVersion).dll" >
122
+ <ParameterGroup >
123
+ <EnvKey ParameterType =" System.String" Required =" true" />
124
+ <EnvValue ParameterType =" System.String" Required =" true" />
125
+ </ParameterGroup >
126
+ <Task >
127
+ <Using Namespace =" System" />
128
+ <Code Type =" Fragment" Language =" cs" >
129
+ <![CDATA[
130
+ try {
131
+ Environment.SetEnvironmentVariable(EnvKey, EnvValue, System.EnvironmentVariableTarget.Process);
132
+ }
133
+ catch {
134
+ }
135
+ ]]>
136
+ </Code >
137
+ </Task >
138
+ </UsingTask >
139
+ </Project >
0 commit comments