Skip to content

Commit b9672a9

Browse files
committed
Enabled NuGet Package Restore
I did this so I don't have to store NuGet Packages in my revision control (Git), but have not yet removed the packages from the revision control repository.
1 parent d80f582 commit b9672a9

File tree

6 files changed

+158
-0
lines changed

6 files changed

+158
-0
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.targets

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
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+
<!-- Download NuGet.exe if it does not already exist -->
13+
<DownloadNuGetExe Condition=" '$(DownloadNuGetExe)' == '' ">false</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.v4.0.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.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>
139+
</Project>

.nuget/nuget.exe

605 KB
Binary file not shown.

POS.Domain/POS.Domain.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
<AssemblyName>POS.Domain</AssemblyName>
1313
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
1414
<FileAlignment>512</FileAlignment>
15+
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
16+
<RestorePackages>true</RestorePackages>
1517
</PropertyGroup>
1618
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1719
<DebugSymbols>true</DebugSymbols>
@@ -87,6 +89,7 @@
8789
</EmbeddedResource>
8890
</ItemGroup>
8991
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
92+
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />
9093
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
9194
Other similar extension points exist, see Microsoft.Common.targets.
9295
<Target Name="BeforeBuild">

POS.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "POS.Tests", "POS.Tests\POS.
77
EndProject
88
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "POS.Domain", "POS.Domain\POS.Domain.csproj", "{5AE451AA-73A6-4C36-8D1C-F78A03EB93D9}"
99
EndProject
10+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{A8A500E1-C3FD-4DFB-BD9F-4B1807CD41E8}"
11+
ProjectSection(SolutionItems) = preProject
12+
.nuget\NuGet.Config = .nuget\NuGet.Config
13+
.nuget\nuget.exe = .nuget\nuget.exe
14+
.nuget\NuGet.targets = .nuget\NuGet.targets
15+
EndProjectSection
16+
EndProject
1017
Global
1118
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1219
Debug|Any CPU = Debug|Any CPU

POS/POS.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
1616
<MvcBuildViews>false</MvcBuildViews>
1717
<UseIISExpress>false</UseIISExpress>
18+
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
19+
<RestorePackages>true</RestorePackages>
1820
</PropertyGroup>
1921
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
2022
<DebugSymbols>true</DebugSymbols>
@@ -274,4 +276,5 @@
274276
</FlavorProperties>
275277
</VisualStudio>
276278
</ProjectExtensions>
279+
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />
277280
</Project>

0 commit comments

Comments
 (0)