Skip to content

Commit

Permalink
First package restore from within Visual Studio - references #130
Browse files Browse the repository at this point in the history
  • Loading branch information
forki committed Sep 20, 2014
1 parent 3f8c4ee commit a29b9f6
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,4 @@ release.cmd
localpackages/
paket-files
*.orig
paket.exe
.paket/paket.exe
File renamed without changes.
65 changes: 65 additions & 0 deletions .paket/paket.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">$(MSBuildProjectDirectory)\..\</SolutionDir>

<!-- Enable the restore command to run before builds -->
<RestorePackages Condition=" '$(RestorePackages)' == '' ">false</RestorePackages>

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

<PropertyGroup Condition=" '$(OS)' == 'Windows_NT'">
<!-- Windows specific commands -->
<PaketToolsPath>$([System.IO.Path]::Combine($(SolutionDir), ".paket"))</PaketToolsPath>
</PropertyGroup>

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

<PropertyGroup>
<!-- Paket command -->
<PaketExePath Condition=" '$(PaketExePath)' == '' ">$(PaketToolsPath)\paket.exe</PaketExePath>
<PaketBootStrapperExePath Condition=" '$(PaketBootStrapperExePath)' == '' ">$(PaketToolsPath)\paket.bootstrapper.exe</PaketBootStrapperExePath>

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

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

<!-- Commands -->
<RestoreCommand>$(PaketCommand) install</RestoreCommand>
<DownloadPaketCommand>$(PaketBootStrapperCommand) </DownloadPaketCommand>

<!-- We need to ensure packages are restored prior to assembly resolve -->
<BuildDependsOn Condition="$(RestorePackages) == 'true'">
RestorePackages;
$(BuildDependsOn);
</BuildDependsOn>
</PropertyGroup>

<Target Name="CheckPrerequisites">
<!-- Raise an error if we're unable to locate paket.exe -->
<Error Condition="'$(DownloadPaket)' != 'true' AND !Exists('$(PaketExePath)')" Text="Unable to locate '$(PaketExePath)'" />
<!--
Take advantage of MsBuild's build dependency tracking to make sure that we only ever download paket.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="DownloadPaket" Projects="$(MSBuildThisFileFullPath)" Properties="Configuration=NOT_IMPORTANT;DownloadPaket=$(DownloadPaket)" />
</Target>

<Target Name="DownloadPaket">
<Exec Command="$(DownloadPaketCommand)" />
</Target>

<Target Name="RestorePackages" DependsOnTargets="CheckPrerequisites">
<Exec Command="$(RestoreCommand)"
WorkingDirectory="$(SolutionDir)" />

This comment has been minimized.

Copy link
@dsyme

dsyme Sep 26, 2014

Contributor

I'm not sure this is correct if building a project using "msbuild" within a solution.

In this case, SolutionDir typically gets set by the project file like this:

<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
However when doing that, the WorkingDirectory becomes "....", and the RestoreCommand becomes ".....paket\paket.exe", which is wrong - it is now looking up four levels for paket.exe.

See #172

This comment has been minimized.

Copy link
@forki

forki via email Sep 26, 2014

Author Member
</Target>

</Project>
4 changes: 2 additions & 2 deletions build.cmd
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
@echo off
cls

paket.bootstrapper.exe
.paket\paket.bootstrapper.exe
if errorlevel 1 (
exit /b %errorlevel%
)

paket.exe install -v
.paket\paket.exe install -v
if errorlevel 1 (
exit /b %errorlevel%
)
Expand Down
4 changes: 2 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/bin/bash

mono paket.bootstrapper.exe
mono .paket/paket.bootstrapper.exe
exit_code=$?
if [ $exit_code -ne 0 ]; then
exit $exit_code
fi

mono paket.exe install -v
mono .paket/paket.exe install -v
exit_code=$?
if [ $exit_code -ne 0 ]; then
exit $exit_code
Expand Down
3 changes: 2 additions & 1 deletion src/Paket.Bootstrapper/Paket.Bootstrapper.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
Expand Down Expand Up @@ -53,4 +53,5 @@
<Target Name="AfterBuild">
</Target>
-->
<Import Project="$(SolutionDir)\.paket\paket.targets" />
</Project>
2 changes: 2 additions & 0 deletions src/Paket/Paket.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
<Compile Include="InstallProcess.fs" />
<Compile Include="NugetConvert.fs" />
<Compile Include="FindOutdated.fs" />
<Compile Include="VSIntegration.fs" />
<Compile Include="Program.fs" />
<None Include="paket.references" />
</ItemGroup>
Expand All @@ -105,6 +106,7 @@
<Target Name="AfterBuild">
</Target>
-->
<Import Project="$(SolutionDir)\.paket\paket.targets" />
<Choose>
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And $(TargetFrameworkVersion) == 'v2.0'">
<ItemGroup>
Expand Down
5 changes: 5 additions & 0 deletions src/Paket/VSIntegration.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Paket.VSIntegration

open System.IO

Directory.CreateDirectory(@"D:\code\Paket\.paket")
1 change: 1 addition & 0 deletions tests/Paket.Tests/Paket.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
<Target Name="AfterBuild">
</Target>
-->
<Import Project="$(SolutionDir)\.paket\paket.targets" />
<Choose>
<When Condition="true">
<ItemGroup>
Expand Down

0 comments on commit a29b9f6

Please sign in to comment.