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