paket.targets 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  3. <PropertyGroup>
  4. <!-- Enable the restore command to run before builds -->
  5. <RestorePackages Condition=" '$(RestorePackages)' == '' ">true</RestorePackages>
  6. <PaketToolsPath>$(MSBuildThisFileDirectory)</PaketToolsPath>
  7. <PaketRootPath>$(MSBuildThisFileDirectory)..\</PaketRootPath>
  8. <PaketLockFilePath>$(PaketRootPath)paket.lock</PaketLockFilePath>
  9. <PaketRestoreCacheFile>$(PaketRootPath)paket-files\paket.restore.cached</PaketRestoreCacheFile>
  10. <MonoPath Condition="'$(MonoPath)' == '' And Exists('/Library/Frameworks/Mono.framework/Commands/mono')">/Library/Frameworks/Mono.framework/Commands/mono</MonoPath>
  11. <MonoPath Condition="'$(MonoPath)' == ''">mono</MonoPath>
  12. <!-- Disable test for CLI tool completely - overrideable via properties in projects or via environment variables -->
  13. <PaketDisableCliTest Condition=" '$(PaketDisableCliTest)' == '' ">False</PaketDisableCliTest>
  14. </PropertyGroup>
  15. <!-- Resolve how paket should be called -->
  16. <!-- Current priority is: local (1: repo root, 2: .paket folder) => 3: as CLI tool => as bootstrapper (4: proj Bootstrapper style, 5: BootstrapperExeDir) => 6: global path variable -->
  17. <Target Name="SetPaketCommand" >
  18. <!-- Test if paket is available in the standard locations. If so, that takes priority. Case 1/2 - non-windows specific -->
  19. <PropertyGroup Condition=" '$(OS)' != 'Windows_NT' ">
  20. <!-- no windows, try native paket as default, root => tool -->
  21. <PaketExePath Condition=" '$(PaketExePath)' == '' AND Exists('$(PaketRootPath)paket') ">$(PaketRootPath)paket</PaketExePath>
  22. <PaketExePath Condition=" '$(PaketExePath)' == '' AND Exists('$(PaketToolsPath)paket') ">$(PaketToolsPath)paket</PaketExePath>
  23. </PropertyGroup>
  24. <!-- Test if paket is available in the standard locations. If so, that takes priority. Case 2/2 - same across platforms -->
  25. <PropertyGroup>
  26. <!-- root => tool -->
  27. <PaketExePath Condition=" '$(PaketExePath)' == '' AND Exists('$(PaketRootPath)paket.exe') ">$(PaketRootPath)paket.exe</PaketExePath>
  28. <PaketExePath Condition=" '$(PaketExePath)' == '' AND Exists('$(PaketToolsPath)paket.exe') ">$(PaketToolsPath)paket.exe</PaketExePath>
  29. </PropertyGroup>
  30. <!-- If paket hasn't be found in standard locations, test for CLI tool usage. -->
  31. <!-- First test: Is CLI configured to be used in "dotnet-tools.json"? - can result in a false negative; only a positive outcome is reliable. -->
  32. <PropertyGroup Condition=" '$(PaketExePath)' == '' ">
  33. <_DotnetToolsJson Condition="Exists('$(PaketRootPath)/.config/dotnet-tools.json')">$([System.IO.File]::ReadAllText("$(PaketRootPath)/.config/dotnet-tools.json"))</_DotnetToolsJson>
  34. <_ConfigContainsPaket Condition=" '$(_DotnetToolsJson)' != ''">$(_DotnetToolsJson.Contains('"paket"'))</_ConfigContainsPaket>
  35. <_ConfigContainsPaket Condition=" '$(_ConfigContainsPaket)' == ''">false</_ConfigContainsPaket>
  36. </PropertyGroup>
  37. <!-- Second test: Call 'dotnet paket' and see if it returns without an error. Mute all the output. Only run if previous test failed and the test has not been disabled. -->
  38. <!-- WARNING: This method can lead to processes hanging forever, and should be used as little as possible. See https://github.com/fsprojects/Paket/issues/3705 for details. -->
  39. <Exec Condition=" '$(PaketExePath)' == '' AND !$(PaketDisableCliTest) AND !$(_ConfigContainsPaket)" Command="dotnet paket --version" IgnoreExitCode="true" StandardOutputImportance="low" StandardErrorImportance="low" >
  40. <Output TaskParameter="ExitCode" PropertyName="LocalPaketToolExitCode" />
  41. </Exec>
  42. <!-- If paket is installed as CLI use that. Again, only if paket haven't already been found in standard locations. -->
  43. <PropertyGroup Condition=" '$(PaketExePath)' == '' AND ($(_ConfigContainsPaket) OR '$(LocalPaketToolExitCode)' == '0') ">
  44. <_PaketCommand>dotnet paket</_PaketCommand>
  45. </PropertyGroup>
  46. <!-- If neither local files nor CLI tool can be found, final attempt is searching for boostrapper config before falling back to global path variable. -->
  47. <PropertyGroup Condition=" '$(PaketExePath)' == '' AND '$(_PaketCommand)' == '' ">
  48. <!-- Test for bootstrapper setup -->
  49. <PaketExePath Condition=" '$(PaketExePath)' == '' AND '$(PaketBootstrapperStyle)' == 'proj' ">$(PaketToolsPath)paket</PaketExePath>
  50. <PaketExePath Condition=" '$(PaketExePath)' == '' AND Exists('$(PaketBootStrapperExeDir)') ">$(PaketBootStrapperExeDir)paket</PaketExePath>
  51. <!-- If all else fails, use global path approach. -->
  52. <PaketExePath Condition=" '$(PaketExePath)' == ''">paket</PaketExePath>
  53. </PropertyGroup>
  54. <!-- If not using CLI, setup correct execution command. -->
  55. <PropertyGroup Condition=" '$(_PaketCommand)' == '' ">
  56. <_PaketExeExtension>$([System.IO.Path]::GetExtension("$(PaketExePath)"))</_PaketExeExtension>
  57. <_PaketCommand Condition=" '$(_PaketCommand)' == '' AND '$(_PaketExeExtension)' == '.dll' ">dotnet "$(PaketExePath)"</_PaketCommand>
  58. <_PaketCommand Condition=" '$(_PaketCommand)' == '' AND '$(OS)' != 'Windows_NT' AND '$(_PaketExeExtension)' == '.exe' ">$(MonoPath) --runtime=v4.0.30319 "$(PaketExePath)"</_PaketCommand>
  59. <_PaketCommand Condition=" '$(_PaketCommand)' == '' ">"$(PaketExePath)"</_PaketCommand>
  60. </PropertyGroup>
  61. <!-- The way to get a property to be available outside the target is to use this task. -->
  62. <CreateProperty Value="$(_PaketCommand)">
  63. <Output TaskParameter="Value" PropertyName="PaketCommand"/>
  64. </CreateProperty>
  65. </Target>
  66. <Choose> <!-- MyProject.fsproj.paket.references has the highest precedence -->
  67. <When Condition="Exists('$(MSBuildProjectFullPath).paket.references')">
  68. <PropertyGroup>
  69. <PaketReferences>$(MSBuildProjectFullPath).paket.references</PaketReferences>
  70. </PropertyGroup>
  71. </When> <!-- MyProject.paket.references -->
  72. <When Condition="Exists('$(MSBuildProjectDirectory)\$(MSBuildProjectName).paket.references')">
  73. <PropertyGroup>
  74. <PaketReferences>$(MSBuildProjectDirectory)\$(MSBuildProjectName).paket.references</PaketReferences>
  75. </PropertyGroup>
  76. </When> <!-- paket.references -->
  77. <When Condition="Exists('$(MSBuildProjectDirectory)\paket.references')">
  78. <PropertyGroup>
  79. <PaketReferences>$(MSBuildProjectDirectory)\paket.references</PaketReferences>
  80. </PropertyGroup>
  81. </When> <!-- Set to empty if a reference file isn't found matching one of the 3 format options -->
  82. <Otherwise>
  83. <PropertyGroup>
  84. <PaketReferences></PaketReferences>
  85. </PropertyGroup>
  86. </Otherwise>
  87. </Choose>
  88. <PropertyGroup>
  89. <!-- We need to ensure packages are restored prior to assembly resolve -->
  90. <BuildDependsOn Condition="$(RestorePackages) == 'true'">RestorePackages; $(BuildDependsOn);</BuildDependsOn>
  91. </PropertyGroup>
  92. <Target Name="RestorePackages" DependsOnTargets="SetPaketCommand">
  93. <PropertyGroup>
  94. <!-- Commands -->
  95. <RestoreCommand>$(PaketCommand) restore --references-file "$(PaketReferences)"</RestoreCommand>
  96. <PaketRestoreRequired>true</PaketRestoreRequired>
  97. </PropertyGroup>
  98. <PropertyGroup Condition="Exists('$(PaketRestoreCacheFile)') ">
  99. <PaketRestoreCachedHash>$([System.IO.File]::ReadAllText('$(PaketRestoreCacheFile)'))</PaketRestoreCachedHash>
  100. <PaketRestoreLockFileHash>$([System.IO.File]::ReadAllText('$(PaketLockFilePath)'))</PaketRestoreLockFileHash>
  101. <PaketRestoreRequired>true</PaketRestoreRequired>
  102. <PaketRestoreRequired Condition=" '$(PaketRestoreLockFileHash)' == '$(PaketRestoreCachedHash)' ">false</PaketRestoreRequired>
  103. <PaketRestoreRequired Condition=" '$(PaketRestoreLockFileHash)' == '' ">true</PaketRestoreRequired>
  104. </PropertyGroup>
  105. <Exec Command="$(RestoreCommand)"
  106. IgnoreStandardErrorWarningFormat="true"
  107. WorkingDirectory="$(PaketRootPath)"
  108. ContinueOnError="false"
  109. Condition=" '$(PaketRestoreRequired)' == 'true' AND Exists('$(PaketReferences)') AND '$(PaketReferences)' != '' "
  110. />
  111. </Target>
  112. </Project>