|
5 | 5 | <!-- make MSBuild track this file for incremental builds. --> |
6 | 6 | <!-- ref https://blogs.msdn.microsoft.com/msbuild/2005/09/26/how-to-ensure-changes-to-a-custom-target-file-prompt-a-rebuild/ --> |
7 | 7 | <MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects> |
8 | | - |
9 | | - <DetectedMSBuildVersion>$(MSBuildVersion)</DetectedMSBuildVersion> |
10 | | - <DetectedMSBuildVersion Condition="$(MSBuildVersion) == ''">15.0.0</DetectedMSBuildVersion> |
11 | | - <MSBuildSupportsHashing>false</MSBuildSupportsHashing> |
12 | | - <MSBuildSupportsHashing Condition=" '$(DetectedMSBuildVersion)' > '15.8.0' ">true</MSBuildSupportsHashing> |
13 | 8 | <!-- Mark that this target file has been loaded. --> |
14 | 9 | <IsPaketRestoreTargetsFileLoaded>true</IsPaketRestoreTargetsFileLoaded> |
15 | 10 | <PaketToolsPath>$(MSBuildThisFileDirectory)</PaketToolsPath> |
|
78 | 73 | <MSBuild Projects="$(PaketToolsPath)paket.bootstrapper.proj" Targets="Restore" /> |
79 | 74 | </Target> |
80 | 75 |
|
81 | | - <!-- Official workaround for https://docs.microsoft.com/en-us/visualstudio/msbuild/getfilehash-task?view=vs-2019 --> |
82 | | - <UsingTask TaskName="Microsoft.Build.Tasks.GetFileHash" AssemblyName="Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" Condition=" '$(MSBuildSupportsHashing)' == 'true' And '$(DetectedMSBuildVersion)' < '16.0.360' " /> |
83 | | - <UsingTask TaskName="Microsoft.Build.Tasks.VerifyFileHash" AssemblyName="Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" Condition=" '$(MSBuildSupportsHashing)' == 'true' And '$(DetectedMSBuildVersion)' < '16.0.360' " /> |
84 | 76 | <Target Name="PaketRestore" Condition="'$(PaketRestoreDisabled)' != 'True'" BeforeTargets="_GenerateDotnetCliToolReferenceSpecs;_GenerateProjectRestoreGraphPerFramework;_GenerateRestoreGraphWalkPerFramework;CollectPackageReferences" DependsOnTargets="PaketBootstrapping"> |
85 | 77 |
|
86 | | - <!-- Step 1 Check if lockfile is properly restored (if the hash of the lockfile and the cache-file match) --> |
| 78 | + <!-- Step 1 Check if lockfile is properly restored --> |
87 | 79 | <PropertyGroup> |
88 | 80 | <PaketRestoreRequired>true</PaketRestoreRequired> |
89 | 81 | <NoWarn>$(NoWarn);NU1603;NU1604;NU1605;NU1608</NoWarn> |
90 | | - <CacheFilesExist>false</CacheFilesExist> |
91 | | - <CacheFilesExist Condition=" Exists('$(PaketRestoreCacheFile)') And Exists('$(PaketLockFilePath)') ">true</CacheFilesExist> |
92 | 82 | </PropertyGroup> |
93 | 83 |
|
94 | | - <!-- Read the hash of the lockfile --> |
95 | | - <GetFileHash Condition=" '$(MSBuildSupportsHashing)' == 'true' And '$(CacheFilesExist)' == 'true' " Files="$(PaketLockFilePath)" Algorithm="SHA256" HashEncoding="hex" > |
96 | | - <Output TaskParameter="Hash" PropertyName="PaketRestoreLockFileHash" /> |
97 | | - </GetFileHash> |
98 | | - <!-- Read the hash of the cache, which is json, but a very simple key value object --> |
99 | | - <PropertyGroup Condition=" '$(MSBuildSupportsHashing)' == 'true' And '$(CacheFilesExist)' == 'true' "> |
100 | | - <PaketRestoreCachedContents>$([System.IO.File]::ReadAllText('$(PaketRestoreCacheFile)'))</PaketRestoreCachedContents> |
101 | | - </PropertyGroup> |
102 | | - <ItemGroup Condition=" '$(MSBuildSupportsHashing)' == 'true' And '$(CacheFilesExist)' == 'true' "> |
103 | | - <!-- Parse our simple 'paket.restore.cached' json ...--> |
104 | | - <PaketRestoreCachedSplitObject Include="$([System.Text.RegularExpressions.Regex]::Split(`$(PaketRestoreCachedContents)`, `{|}|,`))"></PaketRestoreCachedSplitObject> |
105 | | - <!-- Keep Key, Value ItemGroup--> |
106 | | - <PaketRestoreCachedKeyValue Include="@(PaketRestoreCachedSplitObject)" |
107 | | - Condition=" $([System.Text.RegularExpressions.Regex]::Split(`%(Identity)`, `": "`).Length) > 1 "> |
108 | | - <Key>$([System.Text.RegularExpressions.Regex]::Split(`%(Identity)`, `": "`)[0].Replace(`"`, ``).Replace(` `, ``))</Key> |
109 | | - <Value>$([System.Text.RegularExpressions.Regex]::Split(`%(Identity)`, `": "`)[1].Replace(`"`, ``).Replace(` `, ``))</Value> |
110 | | - </PaketRestoreCachedKeyValue> |
111 | | - </ItemGroup> |
112 | | - <PropertyGroup Condition=" '$(MSBuildSupportsHashing)' == 'true' And '$(CacheFilesExist)' == 'true' "> |
113 | | - <!-- Retrieve the hashes we are interested in --> |
114 | | - <PackagesDownloadedHash Condition=" '%(PaketRestoreCachedKeyValue.Key)' == 'packagesDownloadedHash' ">%(PaketRestoreCachedKeyValue.Value)</PackagesDownloadedHash> |
115 | | - <ProjectsRestoredHash Condition=" '%(PaketRestoreCachedKeyValue.Key)' == 'projectsRestoredHash' ">%(PaketRestoreCachedKeyValue.Value)</ProjectsRestoredHash> |
| 84 | + <!-- Because ReadAllText is slow on osx/linux, try to find shasum and awk --> |
| 85 | + <PropertyGroup> |
| 86 | + <PaketRestoreCachedHasher Condition="'$(OS)' != 'Windows_NT' And '$(PaketRestoreCachedHasher)' == '' And Exists('/usr/bin/shasum') And Exists('/usr/bin/awk')">/usr/bin/shasum "$(PaketRestoreCacheFile)" | /usr/bin/awk '{ print $1 }'</PaketRestoreCachedHasher> |
| 87 | + <PaketRestoreLockFileHasher Condition="'$(OS)' != 'Windows_NT' And '$(PaketRestoreLockFileHash)' == '' And Exists('/usr/bin/shasum') And Exists('/usr/bin/awk')">/usr/bin/shasum "$(PaketLockFilePath)" | /usr/bin/awk '{ print $1 }'</PaketRestoreLockFileHasher> |
116 | 88 | </PropertyGroup> |
117 | 89 |
|
118 | | - <PropertyGroup Condition=" '$(MSBuildSupportsHashing)' == 'true' And '$(CacheFilesExist)' == 'true' "> |
119 | | - <!-- If the restire file doesn't exist we need to restore, otherwise only if hashes don't match --> |
| 90 | + <!-- If shasum and awk exist get the hashes --> |
| 91 | + <Exec StandardOutputImportance="Low" Condition=" '$(PaketRestoreCachedHasher)' != '' " Command="$(PaketRestoreCachedHasher)" ConsoleToMSBuild='true'> |
| 92 | + <Output TaskParameter="ConsoleOutput" PropertyName="PaketRestoreCachedHash" /> |
| 93 | + </Exec> |
| 94 | + <Exec StandardOutputImportance="Low" Condition=" '$(PaketRestoreLockFileHasher)' != '' " Command="$(PaketRestoreLockFileHasher)" ConsoleToMSBuild='true'> |
| 95 | + <Output TaskParameter="ConsoleOutput" PropertyName="PaketRestoreLockFileHash" /> |
| 96 | + </Exec> |
| 97 | + |
| 98 | + <!-- Debug whats going on --> |
| 99 | + <Message Importance="low" Text="calling paket restore with targetframework=$(TargetFramework) targetframeworks=$(TargetFrameworks)" /> |
| 100 | + |
| 101 | + <PropertyGroup Condition="Exists('$(PaketRestoreCacheFile)') "> |
| 102 | + <!-- if no hash has been done yet fall back to just reading in the files and comparing them --> |
| 103 | + <PaketRestoreCachedHash Condition=" '$(PaketRestoreCachedHash)' == '' ">$([System.IO.File]::ReadAllText('$(PaketRestoreCacheFile)'))</PaketRestoreCachedHash> |
| 104 | + <PaketRestoreLockFileHash Condition=" '$(PaketRestoreLockFileHash)' == '' ">$([System.IO.File]::ReadAllText('$(PaketLockFilePath)'))</PaketRestoreLockFileHash> |
120 | 105 | <PaketRestoreRequired>true</PaketRestoreRequired> |
121 | | - <PaketRestoreRequired Condition=" '$(PaketRestoreLockFileHash)' == '$(ProjectsRestoredHash)' ">false</PaketRestoreRequired> |
| 106 | + <PaketRestoreRequired Condition=" '$(PaketRestoreLockFileHash)' == '$(PaketRestoreCachedHash)' ">false</PaketRestoreRequired> |
122 | 107 | <PaketRestoreRequired Condition=" '$(PaketRestoreLockFileHash)' == '' ">true</PaketRestoreRequired> |
123 | 108 | </PropertyGroup> |
124 | 109 |
|
|
131 | 116 | </PropertyGroup> |
132 | 117 |
|
133 | 118 | <!-- Do a global restore if required --> |
134 | | - <Warning Text="This version of MSBuild (we assume '$(DetectedMSBuildVersion)' or older) doesn't support GetFileHash, so paket fast restore is disabled." Condition=" '$(MSBuildSupportsHashing)' != 'true' " /> |
135 | | - <Error Text="Stop build because of PAKET_ERROR_ON_MSBUILD_EXEC and we always call the bootstrapper" Condition=" '$(PAKET_ERROR_ON_MSBUILD_EXEC)' == 'true' AND '$(PaketBootstrapperStyle)' == 'classic' AND Exists('$(PaketBootStrapperExePath)') AND !(Exists('$(PaketExePath)'))" /> |
136 | 119 | <Exec Command='$(PaketBootStrapperCommand)' Condition=" '$(PaketBootstrapperStyle)' == 'classic' AND Exists('$(PaketBootStrapperExePath)') AND !(Exists('$(PaketExePath)'))" ContinueOnError="false" /> |
137 | | - <Error Text="Stop build because of PAKET_ERROR_ON_MSBUILD_EXEC and we need a full restore (hashes don't match)" Condition=" '$(PAKET_ERROR_ON_MSBUILD_EXEC)' == 'true' AND '$(PaketRestoreRequired)' == 'true' AND '$(PaketDisableGlobalRestore)' != 'true'" /> |
138 | 120 | <Exec Command='$(PaketCommand) restore' Condition=" '$(PaketRestoreRequired)' == 'true' AND '$(PaketDisableGlobalRestore)' != 'true' " ContinueOnError="false" /> |
139 | 121 |
|
140 | 122 | <!-- Step 2 Detect project specific changes --> |
|
144 | 126 | <MyTargetFrameworks Condition="'$(TargetFrameworks)' != '' AND '$(TargetFramework)' == '' " Include="$(TargetFrameworks)"></MyTargetFrameworks> |
145 | 127 | <PaketResolvedFilePaths Include="@(MyTargetFrameworks -> '$(PaketIntermediateOutputPath)\$(MSBuildProjectFile).%(Identity).paket.resolved')"></PaketResolvedFilePaths> |
146 | 128 | </ItemGroup> |
147 | | - |
| 129 | + <Message Importance="low" Text="MyTargetFrameworks=@(MyTargetFrameworks) PaketResolvedFilePaths=@(PaketResolvedFilePaths)" /> |
148 | 130 | <PropertyGroup> |
149 | 131 | <PaketReferencesCachedFilePath>$(PaketIntermediateOutputPath)\$(MSBuildProjectFile).paket.references.cached</PaketReferencesCachedFilePath> |
150 | 132 | <!-- MyProject.fsproj.paket.references has the highest precedence --> |
|
181 | 163 |
|
182 | 164 | <!-- Step 3 Restore project specific stuff if required --> |
183 | 165 | <Message Condition=" '$(PaketRestoreRequired)' == 'true' " Importance="low" Text="Detected a change ('$(PaketRestoreRequiredReason)') in the project file '$(MSBuildProjectFullPath)', calling paket restore" /> |
184 | | - <Error Text="Stop build because of PAKET_ERROR_ON_MSBUILD_EXEC and we detected a change ('$(PaketRestoreRequiredReason)') in the project file '$(MSBuildProjectFullPath)'" Condition=" '$(PAKET_ERROR_ON_MSBUILD_EXEC)' == 'true' AND '$(PaketRestoreRequired)' == 'true' " /> |
185 | 166 | <Exec Command='$(PaketCommand) restore --project "$(MSBuildProjectFullPath)" --output-path "$(PaketIntermediateOutputPath)" --target-framework "$(TargetFrameworks)"' Condition=" '$(PaketRestoreRequired)' == 'true' AND '$(TargetFramework)' == '' " ContinueOnError="false" /> |
186 | 167 | <Exec Command='$(PaketCommand) restore --project "$(MSBuildProjectFullPath)" --output-path "$(PaketIntermediateOutputPath)" --target-framework "$(TargetFramework)"' Condition=" '$(PaketRestoreRequired)' == 'true' AND '$(TargetFramework)' != '' " ContinueOnError="false" /> |
187 | 168 |
|
|
243 | 224 | <Target Name="PaketDisableDirectPack" AfterTargets="_IntermediatePack" BeforeTargets="GenerateNuspec" Condition="('$(IsPackable)' == '' Or '$(IsPackable)' == 'true') And Exists('$(PaketIntermediateOutputPath)/$(MSBuildProjectFile).references')" > |
244 | 225 | <PropertyGroup> |
245 | 226 | <ContinuePackingAfterGeneratingNuspec>false</ContinuePackingAfterGeneratingNuspec> |
| 227 | + <DetectedMSBuildVersion>$(MSBuildVersion)</DetectedMSBuildVersion> |
| 228 | + <DetectedMSBuildVersion Condition="$(MSBuildVersion) == ''">15.8.0</DetectedMSBuildVersion> |
246 | 229 | </PropertyGroup> |
247 | 230 | </Target> |
248 | 231 |
|
|
269 | 252 | </PropertyGroup> |
270 | 253 |
|
271 | 254 | <ItemGroup> |
272 | | - <_NuspecFiles Include="$(AdjustedNuspecOutputPath)\*.$(PackageVersion.Split(`+`)[0]).nuspec"/> |
| 255 | + <_NuspecFiles Include="$(AdjustedNuspecOutputPath)\*.nuspec"/> |
273 | 256 | </ItemGroup> |
274 | 257 |
|
275 | | - <Error Text="Error Because of PAKET_ERROR_ON_MSBUILD_EXEC (not calling fix-nuspecs)" Condition=" '$(PAKET_ERROR_ON_MSBUILD_EXEC)' == 'true' " /> |
276 | | - <Exec Condition="@(_NuspecFiles) != ''" Command='$(PaketCommand) fix-nuspecs files "@(_NuspecFiles)" project-file "$(PaketProjectFile)" ' /> |
277 | | - <Error Condition="@(_NuspecFiles) == ''" Text='Could not find nuspec files in "$(AdjustedNuspecOutputPath)" (Version: "$(PackageVersion)"), therefore we cannot call "paket fix-nuspecs" and have to error out!' /> |
| 258 | + <Exec Command='$(PaketCommand) fix-nuspecs files "@(_NuspecFiles)" project-file "$(PaketProjectFile)" ' Condition="@(_NuspecFiles) != ''" /> |
278 | 259 |
|
279 | 260 | <ConvertToAbsolutePath Condition="@(_NuspecFiles) != ''" Paths="@(_NuspecFiles)"> |
280 | 261 | <Output TaskParameter="AbsolutePaths" PropertyName="NuspecFileAbsolutePath" /> |
|
0 commit comments