Skip to content

Commit 8abdb7f

Browse files
committed
enable nuget package restore on build
1 parent f13de36 commit 8abdb7f

File tree

5 files changed

+174
-26
lines changed

5 files changed

+174
-26
lines changed

.nuget/NuGet.Config

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<solution>
4+
<add key="disableSourceControlIntegration" value="true" />
5+
</solution>
6+
</configuration>

.nuget/NuGet.exe

760 KB
Binary file not shown.

.nuget/NuGet.targets

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
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>

FluentCommandLineParser.Tests/FluentCommandLineParser.Tests.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<TargetFrameworkProfile>
1616
</TargetFrameworkProfile>
1717
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
18+
<RestorePackages>true</RestorePackages>
1819
</PropertyGroup>
1920
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
2021
<DebugSymbols>true</DebugSymbols>
@@ -168,6 +169,7 @@
168169
</None>
169170
</ItemGroup>
170171
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
172+
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
171173
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
172174
Other similar extension points exist, see Microsoft.Common.targets.
173175
<Target Name="BeforeBuild">

FluentCommandLineParser.sln

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,33 @@
1-
2-
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 2012
4-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FluentCommandLineParser", "FluentCommandLineParser\FluentCommandLineParser.csproj", "{74CDFA61-81D8-40F2-B536-949BABA15D3E}"
5-
EndProject
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FluentCommandLineParser.Tests", "FluentCommandLineParser.Tests\FluentCommandLineParser.Tests.csproj", "{A2546703-0B86-4515-BE5B-FAF85B756BDC}"
7-
EndProject
8-
Global
9-
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10-
Debug|Any CPU = Debug|Any CPU
11-
Release|Any CPU = Release|Any CPU
12-
EndGlobalSection
13-
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14-
{74CDFA61-81D8-40F2-B536-949BABA15D3E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15-
{74CDFA61-81D8-40F2-B536-949BABA15D3E}.Debug|Any CPU.Build.0 = Debug|Any CPU
16-
{74CDFA61-81D8-40F2-B536-949BABA15D3E}.Release|Any CPU.ActiveCfg = Release|Any CPU
17-
{74CDFA61-81D8-40F2-B536-949BABA15D3E}.Release|Any CPU.Build.0 = Release|Any CPU
18-
{A2546703-0B86-4515-BE5B-FAF85B756BDC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
19-
{A2546703-0B86-4515-BE5B-FAF85B756BDC}.Debug|Any CPU.Build.0 = Debug|Any CPU
20-
{A2546703-0B86-4515-BE5B-FAF85B756BDC}.Release|Any CPU.ActiveCfg = Release|Any CPU
21-
{A2546703-0B86-4515-BE5B-FAF85B756BDC}.Release|Any CPU.Build.0 = Release|Any CPU
22-
EndGlobalSection
23-
GlobalSection(SolutionProperties) = preSolution
24-
HideSolutionNode = FALSE
25-
EndGlobalSection
26-
EndGlobal
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 2012
4+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FluentCommandLineParser", "FluentCommandLineParser\FluentCommandLineParser.csproj", "{74CDFA61-81D8-40F2-B536-949BABA15D3E}"
5+
EndProject
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FluentCommandLineParser.Tests", "FluentCommandLineParser.Tests\FluentCommandLineParser.Tests.csproj", "{A2546703-0B86-4515-BE5B-FAF85B756BDC}"
7+
EndProject
8+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{D8DCB1C2-5F18-4F40-A583-723975F89C1A}"
9+
ProjectSection(SolutionItems) = preProject
10+
.nuget\NuGet.Config = .nuget\NuGet.Config
11+
.nuget\NuGet.exe = .nuget\NuGet.exe
12+
.nuget\NuGet.targets = .nuget\NuGet.targets
13+
EndProjectSection
14+
EndProject
15+
Global
16+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
17+
Debug|Any CPU = Debug|Any CPU
18+
Release|Any CPU = Release|Any CPU
19+
EndGlobalSection
20+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
21+
{74CDFA61-81D8-40F2-B536-949BABA15D3E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
22+
{74CDFA61-81D8-40F2-B536-949BABA15D3E}.Debug|Any CPU.Build.0 = Debug|Any CPU
23+
{74CDFA61-81D8-40F2-B536-949BABA15D3E}.Release|Any CPU.ActiveCfg = Release|Any CPU
24+
{74CDFA61-81D8-40F2-B536-949BABA15D3E}.Release|Any CPU.Build.0 = Release|Any CPU
25+
{A2546703-0B86-4515-BE5B-FAF85B756BDC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
26+
{A2546703-0B86-4515-BE5B-FAF85B756BDC}.Debug|Any CPU.Build.0 = Debug|Any CPU
27+
{A2546703-0B86-4515-BE5B-FAF85B756BDC}.Release|Any CPU.ActiveCfg = Release|Any CPU
28+
{A2546703-0B86-4515-BE5B-FAF85B756BDC}.Release|Any CPU.Build.0 = Release|Any CPU
29+
EndGlobalSection
30+
GlobalSection(SolutionProperties) = preSolution
31+
HideSolutionNode = FALSE
32+
EndGlobalSection
33+
EndGlobal

0 commit comments

Comments
 (0)