Skip to content

Commit

Permalink
Updating nuget.exe and target file in solution
Browse files Browse the repository at this point in the history
  • Loading branch information
pranavkm committed Oct 12, 2012
1 parent 8e9f3f9 commit 2f25307
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 72 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -20,4 +20,5 @@ App_Data/
/artifacts /artifacts
msbuild.log msbuild.log
_app/ _app/
*.ncrunchsolution *.ncrunchsolution
nuget.exe
Binary file removed .nuget/NuGet.exe
Binary file not shown.
201 changes: 136 additions & 65 deletions .nuget/NuGet.targets
@@ -1,79 +1,150 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup> <PropertyGroup>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">$(MSBuildProjectDirectory)\..\</SolutionDir> <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">$(MSBuildProjectDirectory)\..\</SolutionDir>
</PropertyGroup>
<!-- Enable the restore command to run before builds -->
<RestorePackages Condition=" '$(RestorePackages)' == '' ">false</RestorePackages>


<PropertyGroup Condition=" '$(OS)' == 'Windows_NT'"> <!-- Property that enables building a package from a project -->
<!-- Windows specific commands --> <BuildPackage Condition=" '$(BuildPackage)' == '' ">false</BuildPackage>
<NuGetToolsPath>$([System.IO.Path]::Combine($(SolutionDir), ".nuget"))</NuGetToolsPath>
<PackagesConfig>$([System.IO.Path]::Combine($(ProjectDir), "packages.config"))</PackagesConfig>
<PackagesDir>$([System.IO.Path]::Combine($(SolutionDir), "packages"))</PackagesDir>
</PropertyGroup>

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

<Import Project="$(NuGetToolsPath)\sources" />

<PropertyGroup>
<!-- NuGet command -->
<NuGetExePath>$(NuGetToolsPath)\nuget.exe</NuGetExePath>
<NuGetCommand Condition=" '$(OS)' == 'Windows_NT'">"$(NuGetExePath)"</NuGetCommand>
<NuGetCommand Condition=" '$(OS)' != 'Windows_NT' ">mono --runtime=v4.0.30319 $(NuGetExePath)</NuGetCommand>


<PackageOutputDir Condition="$(PackageOutputDir) == ''">$(TargetDir.Trim('\\'))</PackageOutputDir> <!-- Determines if package restore consent is required to restore packages -->
<RequireRestoreConsent>false</RequireRestoreConsent>

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

<ItemGroup Condition=" '$(PackageSources)' == '' ">
<!-- Package sources used to restore packages. By default will used the registered sources under %APPDATA%\NuGet\NuGet.Config -->
<PackageSource Include="http://www.myget.org/F/kudu/" />
<PackageSource Include="https://nuget.org/api/v2/" />
</ItemGroup>


<!-- Package sources used to restore packages. By default will used the registered sources under %APPDATA%\NuGet\NuGet.Config --> <PropertyGroup Condition=" '$(OS)' == 'Windows_NT'">
<PackageSources Condition="$(PackageSources) == ''">""</PackageSources> <!-- Windows specific commands -->
<NuGetToolsPath>$([System.IO.Path]::Combine($(SolutionDir), ".nuget"))</NuGetToolsPath>
<PackagesConfig>$([System.IO.Path]::Combine($(ProjectDir), "packages.config"))</PackagesConfig>
<PackagesDir>$([System.IO.Path]::Combine($(SolutionDir), "packages"))</PackagesDir>
</PropertyGroup>

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

<PropertyGroup>
<!-- NuGet command -->
<NuGetExePath Condition=" '$(NuGetExePath)' == '' ">$(NuGetToolsPath)\nuget.exe</NuGetExePath>
<PackageSources Condition=" $(PackageSources) == '' ">@(PackageSource)</PackageSources>

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


<!-- Enable the restore command to run before builds --> <PackageOutputDir Condition="$(PackageOutputDir) == ''">$(TargetDir.Trim('\\'))</PackageOutputDir>
<RestorePackages Condition="$(RestorePackages) == ''">false</RestorePackages>
<RequireConsentSwitch Condition=" $(RequireRestoreConsent) == 'true' ">-RequireConsent</RequireConsentSwitch>
<!-- Commands -->
<RestoreCommand>$(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(RequireConsentSwitch) -o "$(PackagesDir)"</RestoreCommand>
<BuildCommand>$(NuGetCommand) pack "$(ProjectPath)" -p Configuration=$(Configuration) -o "$(PackageOutputDir)" -symbols</BuildCommand>


<!-- Property that enables building a package from a project --> <!-- We need to ensure packages are restored prior to assembly resolve -->
<BuildPackage Condition="$(BuildPackage) == ''">false</BuildPackage> <ResolveReferencesDependsOn Condition="$(RestorePackages) == 'true'">
RestorePackages;
$(ResolveReferencesDependsOn);
</ResolveReferencesDependsOn>


<!-- Commands --> <!-- Make the build depend on restore packages -->
<RestoreCommand>$(NuGetCommand) install "$(PackagesConfig)" -source $(PackageSources) -o "$(PackagesDir)"</RestoreCommand> <BuildDependsOn Condition="$(BuildPackage) == 'true'">
<BuildCommand>$(NuGetCommand) pack "$(ProjectPath)" -p Configuration=$(Configuration) -o "$(PackageOutputDir)" -symbols</BuildCommand> $(BuildDependsOn);
BuildPackage;
</BuildDependsOn>
</PropertyGroup>


<!-- Make the build depend on restore packages --> <Target Name="CheckPrerequisites">
<BuildDependsOn Condition="$(RestorePackages) == 'true'"> <!-- Raise an error if we're unable to locate nuget.exe -->
RestorePackages; <Error Condition="'$(DownloadNuGetExe)' != 'true' AND !Exists('$(NuGetExePath)')" Text="Unable to locate '$(NuGetExePath)'" />
$(BuildDependsOn); <SetEnvironmentVariable EnvKey="VisualStudioVersion" EnvValue="$(VisualStudioVersion)" Condition=" '$(VisualStudioVersion)' != '' AND '$(OS)' == 'Windows_NT' " />
</BuildDependsOn> <!--
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>


<!-- Make the build depend on restore packages --> <Target Name="_DownloadNuGet">
<BuildDependsOn Condition="$(BuildPackage) == 'true'"> <DownloadNuGet OutputFilename="$(NuGetExePath)" Condition=" '$(DownloadNuGetExe)' == 'true' AND !Exists('$(NuGetExePath)')" />
$(BuildDependsOn); </Target>
BuildPackage;
</BuildDependsOn>
</PropertyGroup>


<Target Name="CheckPrerequisites"> <Target Name="RestorePackages" DependsOnTargets="CheckPrerequisites">
<!-- Raise an error if we're unable to locate nuget.exe --> <Exec Command="$(RestoreCommand)"
<Error Condition="!Exists('$(NuGetExePath)')" Text="Unable to locate '$(NuGetExePath)'" /> Condition="'$(OS)' != 'Windows_NT' And Exists('$(PackagesConfig)')" />
</Target>
<Exec Command="$(RestoreCommand)"
LogStandardErrorAsError="true"
Condition="'$(OS)' == 'Windows_NT' And Exists('$(PackagesConfig)')" />
</Target>


<Target Name="RestorePackages" DependsOnTargets="CheckPrerequisites"> <Target Name="BuildPackage" DependsOnTargets="CheckPrerequisites">
<Exec Command="$(RestoreCommand)" <Exec Command="$(BuildCommand)"
Condition="'$(OS)' != 'Windows_NT' And Exists('$(PackagesConfig)')" /> Condition=" '$(OS)' != 'Windows_NT' " />


<Exec Command="$(RestoreCommand)" <Exec Command="$(BuildCommand)"
LogStandardErrorAsError="true" LogStandardErrorAsError="true"
Condition="'$(OS)' == 'Windows_NT' And Exists('$(PackagesConfig)')" /> Condition=" '$(OS)' == 'Windows_NT' " />
</Target> </Target>

<UsingTask TaskName="DownloadNuGet" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
<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);
<Target Name="BuildPackage" DependsOnTargets="CheckPrerequisites"> Log.LogMessage("Downloading latest version of NuGet.exe...");
<Exec Command="$(BuildCommand)" WebClient webClient = new WebClient();
Condition=" '$(OS)' != 'Windows_NT' " /> webClient.DownloadFile("https://nuget.org/nuget.exe", OutputFilename);

<Exec Command="$(BuildCommand)" return true;
LogStandardErrorAsError="true" }
Condition=" '$(OS)' == 'Windows_NT' " /> catch (Exception ex) {
</Target> Log.LogErrorFromException(ex);
return false;
}
]]>
</Code>
</Task>
</UsingTask>

<UsingTask TaskName="SetEnvironmentVariable" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
<ParameterGroup>
<EnvKey ParameterType="System.String" Required="true" />
<EnvValue ParameterType="System.String" Required="true" />
</ParameterGroup>
<Task>
<Using Namespace="System" />
<Code Type="Fragment" Language="cs">
<![CDATA[
try {
Environment.SetEnvironmentVariable(EnvKey, EnvValue, System.EnvironmentVariableTarget.Process);
}
catch {
}
]]>
</Code>
</Task>
</UsingTask>
</Project> </Project>
6 changes: 0 additions & 6 deletions .nuget/sources

This file was deleted.

0 comments on commit 2f25307

Please sign in to comment.