Skip to content

Commit 15c3de9

Browse files
committed
Update build scripts
1 parent c6a4e9e commit 15c3de9

File tree

4 files changed

+45
-31
lines changed

4 files changed

+45
-31
lines changed

.nuget/NuGet.exe

-788 KB
Binary file not shown.

.nuget/NuGet.targets

+23-29
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@
88

99
<!-- Property that enables building a package from a project -->
1010
<BuildPackage Condition=" '$(BuildPackage)' == '' ">false</BuildPackage>
11+
12+
<!-- Determines if package restore consent is required to restore packages -->
13+
<RequireRestoreConsent Condition=" '$(RequireRestoreConsent)' != 'false' ">true</RequireRestoreConsent>
1114

1215
<!-- Download NuGet.exe if it does not already exist -->
1316
<DownloadNuGetExe Condition=" '$(DownloadNuGetExe)' == '' ">false</DownloadNuGetExe>
1417
</PropertyGroup>
1518

1619
<ItemGroup Condition=" '$(PackageSources)' == '' ">
17-
<!-- Package sources used to restore packages. By default will used the registered sources under %APPDATA%\NuGet\NuGet.Config -->
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 -->
1822
<!--
1923
<PackageSource Include="https://nuget.org/api/v2/" />
2024
<PackageSource Include="https://my-nuget-source/nuget/" />
@@ -25,31 +29,32 @@
2529
<!-- Windows specific commands -->
2630
<NuGetToolsPath>$([System.IO.Path]::Combine($(SolutionDir), ".nuget"))</NuGetToolsPath>
2731
<PackagesConfig>$([System.IO.Path]::Combine($(ProjectDir), "packages.config"))</PackagesConfig>
28-
<PackagesDir>$([System.IO.Path]::Combine($(SolutionDir), "packages"))</PackagesDir>
2932
</PropertyGroup>
3033

3134
<PropertyGroup Condition=" '$(OS)' != 'Windows_NT'">
3235
<!-- We need to launch nuget.exe with the mono command if we're not on windows -->
3336
<NuGetToolsPath>$(SolutionDir).nuget</NuGetToolsPath>
3437
<PackagesConfig>packages.config</PackagesConfig>
35-
<PackagesDir>$(SolutionDir)packages</PackagesDir>
3638
</PropertyGroup>
3739

3840
<PropertyGroup>
3941
<!-- NuGet command -->
40-
<NuGetExePath Condition=" '$(NuGetExePath)' == '' ">$(NuGetToolsPath)\nuget.exe</NuGetExePath>
42+
<NuGetExePath Condition=" '$(NuGetExePath)' == '' ">$(NuGetToolsPath)\NuGet.exe</NuGetExePath>
4143
<PackageSources Condition=" $(PackageSources) == '' ">@(PackageSource)</PackageSources>
4244

4345
<NuGetCommand Condition=" '$(OS)' == 'Windows_NT'">"$(NuGetExePath)"</NuGetCommand>
4446
<NuGetCommand Condition=" '$(OS)' != 'Windows_NT' ">mono --runtime=v4.0.30319 $(NuGetExePath)</NuGetCommand>
4547

4648
<PackageOutputDir Condition="$(PackageOutputDir) == ''">$(TargetDir.Trim('\\'))</PackageOutputDir>
47-
49+
50+
<RequireConsentSwitch Condition=" $(RequireRestoreConsent) == 'true' ">-RequireConsent</RequireConsentSwitch>
51+
<NonInteractiveSwitch Condition=" '$(VisualStudioVersion)' != '' AND '$(OS)' == 'Windows_NT' ">-NonInteractive</NonInteractiveSwitch>
52+
4853
<!-- Commands -->
49-
<RestoreCommand>$(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" -o "$(PackagesDir)"</RestoreCommand>
50-
<BuildCommand>$(NuGetCommand) pack "$(ProjectPath)" -p Configuration=$(Configuration) -o "$(PackageOutputDir)" -symbols</BuildCommand>
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>
5156

52-
<!-- Make the build depend on restore packages -->
57+
<!-- We need to ensure packages are restored prior to assembly resolve -->
5358
<BuildDependsOn Condition="$(RestorePackages) == 'true'">
5459
RestorePackages;
5560
$(BuildDependsOn);
@@ -65,8 +70,16 @@
6570
<Target Name="CheckPrerequisites">
6671
<!-- Raise an error if we're unable to locate nuget.exe -->
6772
<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)')" />
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)')" />
7083
</Target>
7184

7285
<Target Name="RestorePackages" DependsOnTargets="CheckPrerequisites">
@@ -117,23 +130,4 @@
117130
</Code>
118131
</Task>
119132
</UsingTask>
120-
121-
<UsingTask TaskName="SetEnvironmentVariable" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.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>
139133
</Project>

Build.proj

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
<PropertyGroup>
3+
<Root>$(MSBuildThisFileDirectory)</Root>
4+
<SolutionDir>$(Root)</SolutionDir>
5+
</PropertyGroup>
6+
<Target Name="InstallNuGet">
7+
<MakeDir Directories="$(Root)/.nuget" />
8+
<MSBuild Projects="$(Root)/.nuget/NuGet.targets"
9+
Properties="DownloadNuGetExe=true;ProjectDir=$(Root);SolutionDir=$(Root)"
10+
Targets="RestorePackages" />
11+
</Target>
12+
<Target Name="Build" DependsOnTargets="InstallNuGet">
13+
<Exec Command="tools\psake\psake.bat"
14+
WorkingDirectory="$(Root)"
15+
LogStandardErrorAsError="true" />
16+
</Target>
17+
</Project>

build.bat

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1-
echo off
2-
.\tools\psake\psake.bat %*
1+
@echo off
2+
cls
3+
%WINDIR%\Microsoft.Net\Framework\v4.0.30319\MSBuild.exe Build.proj
4+
pause
5+

0 commit comments

Comments
 (0)