Skip to content

Commit

Permalink
Revert "Remove NuGet.targets" (I got too excited)
Browse files Browse the repository at this point in the history
This reverts commit 8cb1a06.
  • Loading branch information
papeh committed Dec 8, 2022
1 parent a3062b6 commit a51c357
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Installer/ChorusMergeModule.wixproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
</WixExtension>
</ItemGroup>
<Import Project="$(WixTargetsPath)" />
<Import Project="NuGet.targets" />

<!-- Pack NuGet Package -->
<PropertyGroup>
Expand All @@ -40,7 +41,7 @@
<Year>$([System.DateTime]::Now.ToString(yyyy))</Year>
</PropertyGroup>

<Target Name="pack">
<Target Name="pack" DependsOnTargets="CheckPrerequisites">
<Exec Command="$(NuGetCommand) pack ChorusMergeModule.nuspec -Version $(GitVersion_NuGetVersion)" />
<Copy SourceFiles="$(PackageId).$(Version).nupkg" DestinationFolder="$(MSBuildThisFileDirectory)../../output" />
</Target>
Expand Down
64 changes: 64 additions & 0 deletions src/Installer/NuGet.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<NuGetToolsPath>$(MSBuildThisFileDirectory)</NuGetToolsPath>

<!-- NuGet command -->
<NuGetExePath Condition=" '$(NuGetExePath)' == '' ">$(NuGetToolsPath)nuget.exe</NuGetExePath>

<NuGetCommand Condition=" '$(OS)' == 'Windows_NT'">"$(NuGetExePath)"</NuGetCommand>
<NuGetCommand Condition=" '$(OS)' != 'Windows_NT' ">mono $(NuGetExePath)</NuGetCommand>
<NuGetDownloadUrl>https://dist.nuget.org/win-x86-commandline/latest/nuget.exe</NuGetDownloadUrl>
</PropertyGroup>

<Target Name="CheckPrerequisites">
<!--
Take advantage of MsBuild's build dependency tracking to make sure that we only ever download nuget.exe once.
This effectively acts as a lock that makes sure that the download operation will only happen once and all
parallel builds will have to wait for it to complete.
-->
<MsBuild Targets="_DownloadNuGet" Projects="$(MSBuildThisFileFullPath)"
Properties="Configuration=NOT_IMPORTANT" />
</Target>

<Target Name="_DownloadNuGet" Condition="!Exists('$(NuGetExePath)')">
<DownloadNuGet OutputFilename="$(NuGetExePath)" Condition="'$(OS)' == 'Windows_NT'" />
<Exec Command="wget $(NuGetDownloadUrl) || curl -O -L $(NuGetDownloadUrl)"
WorkingDirectory="$(NuGetToolsPath)"
Condition="'$(OS)' != 'Windows_NT'" />
</Target>

<UsingTask TaskName="DownloadNuGet" TaskFactory="CodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll"
Condition=" '$(OS)' == 'Windows_NT' ">
<ParameterGroup>
<OutputFilename ParameterType="System.String" Required="true" />
</ParameterGroup>
<Task>
<Reference Include="System.Core" />
<Using Namespace="System" />
<Using Namespace="System.IO" />
<Using Namespace="System.Net" />
<Using Namespace="Microsoft.Build.Framework" />
<Using Namespace="Microsoft.Build.Utilities" />
<Code Type="Fragment" Language="cs">
<![CDATA[
try {
OutputFilename = Path.GetFullPath(OutputFilename);
Log.LogMessage("Downloading latest version of nuget.exe...");
ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12;
WebClient webClient = new WebClient();
webClient.DownloadFile("$(NuGetDownloadUrl)", OutputFilename);
return true;
}
catch (Exception ex) {
Log.LogErrorFromException(ex);
return false;
}
]]>
</Code>
</Task>
</UsingTask>
</Project>

0 comments on commit a51c357

Please sign in to comment.