|
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> |
8 | 13 | <!-- Mark that this target file has been loaded. --> |
9 | 14 | <IsPaketRestoreTargetsFileLoaded>true</IsPaketRestoreTargetsFileLoaded> |
10 | 15 | <PaketToolsPath>$(MSBuildThisFileDirectory)</PaketToolsPath> |
|
73 | 78 | <MSBuild Projects="$(PaketToolsPath)paket.bootstrapper.proj" Targets="Restore" /> |
74 | 79 | </Target> |
75 | 80 |
|
| 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' " /> |
76 | 84 | <Target Name="PaketRestore" Condition="'$(PaketRestoreDisabled)' != 'True'" BeforeTargets="_GenerateDotnetCliToolReferenceSpecs;_GenerateProjectRestoreGraphPerFramework;_GenerateRestoreGraphWalkPerFramework;CollectPackageReferences" DependsOnTargets="PaketBootstrapping"> |
77 | 85 |
|
78 | | - <!-- Step 1 Check if lockfile is properly restored --> |
| 86 | + <!-- Step 1 Check if lockfile is properly restored (if the hash of the lockfile and the cache-file match) --> |
79 | 87 | <PropertyGroup> |
80 | 88 | <PaketRestoreRequired>true</PaketRestoreRequired> |
81 | 89 | <NoWarn>$(NoWarn);NU1603;NU1604;NU1605;NU1608</NoWarn> |
| 90 | + <CacheFilesExist>false</CacheFilesExist> |
| 91 | + <CacheFilesExist Condition=" Exists('$(PaketRestoreCacheFile)') And Exists('$(PaketLockFilePath)') ">true</CacheFilesExist> |
82 | 92 | </PropertyGroup> |
83 | 93 |
|
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> |
| 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> |
88 | 116 | </PropertyGroup> |
89 | 117 |
|
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> |
| 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 --> |
105 | 120 | <PaketRestoreRequired>true</PaketRestoreRequired> |
106 | | - <PaketRestoreRequired Condition=" '$(PaketRestoreLockFileHash)' == '$(PaketRestoreCachedHash)' ">false</PaketRestoreRequired> |
| 121 | + <PaketRestoreRequired Condition=" '$(PaketRestoreLockFileHash)' == '$(ProjectsRestoredHash)' ">false</PaketRestoreRequired> |
107 | 122 | <PaketRestoreRequired Condition=" '$(PaketRestoreLockFileHash)' == '' ">true</PaketRestoreRequired> |
108 | 123 | </PropertyGroup> |
109 | 124 |
|
|
116 | 131 | </PropertyGroup> |
117 | 132 |
|
118 | 133 | <!-- 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)'))" /> |
119 | 136 | <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'" /> |
120 | 138 | <Exec Command='$(PaketCommand) restore' Condition=" '$(PaketRestoreRequired)' == 'true' AND '$(PaketDisableGlobalRestore)' != 'true' " ContinueOnError="false" /> |
121 | 139 |
|
122 | 140 | <!-- Step 2 Detect project specific changes --> |
|
126 | 144 | <MyTargetFrameworks Condition="'$(TargetFrameworks)' != '' AND '$(TargetFramework)' == '' " Include="$(TargetFrameworks)"></MyTargetFrameworks> |
127 | 145 | <PaketResolvedFilePaths Include="@(MyTargetFrameworks -> '$(PaketIntermediateOutputPath)\$(MSBuildProjectFile).%(Identity).paket.resolved')"></PaketResolvedFilePaths> |
128 | 146 | </ItemGroup> |
129 | | - <Message Importance="low" Text="MyTargetFrameworks=@(MyTargetFrameworks) PaketResolvedFilePaths=@(PaketResolvedFilePaths)" /> |
| 147 | + |
130 | 148 | <PropertyGroup> |
131 | 149 | <PaketReferencesCachedFilePath>$(PaketIntermediateOutputPath)\$(MSBuildProjectFile).paket.references.cached</PaketReferencesCachedFilePath> |
132 | 150 | <!-- MyProject.fsproj.paket.references has the highest precedence --> |
|
163 | 181 |
|
164 | 182 | <!-- Step 3 Restore project specific stuff if required --> |
165 | 183 | <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' " /> |
166 | 185 | <Exec Command='$(PaketCommand) restore --project "$(MSBuildProjectFullPath)" --output-path "$(PaketIntermediateOutputPath)" --target-framework "$(TargetFrameworks)"' Condition=" '$(PaketRestoreRequired)' == 'true' AND '$(TargetFramework)' == '' " ContinueOnError="false" /> |
167 | 186 | <Exec Command='$(PaketCommand) restore --project "$(MSBuildProjectFullPath)" --output-path "$(PaketIntermediateOutputPath)" --target-framework "$(TargetFramework)"' Condition=" '$(PaketRestoreRequired)' == 'true' AND '$(TargetFramework)' != '' " ContinueOnError="false" /> |
168 | 187 |
|
|
224 | 243 | <Target Name="PaketDisableDirectPack" AfterTargets="_IntermediatePack" BeforeTargets="GenerateNuspec" Condition="('$(IsPackable)' == '' Or '$(IsPackable)' == 'true') And Exists('$(PaketIntermediateOutputPath)/$(MSBuildProjectFile).references')" > |
225 | 244 | <PropertyGroup> |
226 | 245 | <ContinuePackingAfterGeneratingNuspec>false</ContinuePackingAfterGeneratingNuspec> |
227 | | - <DetectedMSBuildVersion>$(MSBuildVersion)</DetectedMSBuildVersion> |
228 | | - <DetectedMSBuildVersion Condition="$(MSBuildVersion) == ''">15.8.0</DetectedMSBuildVersion> |
229 | 246 | </PropertyGroup> |
230 | 247 | </Target> |
231 | 248 |
|
|
252 | 269 | </PropertyGroup> |
253 | 270 |
|
254 | 271 | <ItemGroup> |
255 | | - <_NuspecFiles Include="$(AdjustedNuspecOutputPath)\*.$(PackageVersion).nuspec"/> |
| 272 | + <_NuspecFiles Include="$(AdjustedNuspecOutputPath)\*.$(PackageVersion.Split(`+`)[0]).nuspec"/> |
256 | 273 | </ItemGroup> |
257 | 274 |
|
258 | | - <Exec Command='$(PaketCommand) fix-nuspecs files "@(_NuspecFiles)" project-file "$(PaketProjectFile)" ' Condition="@(_NuspecFiles) != ''" /> |
| 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!' /> |
259 | 278 |
|
260 | 279 | <ConvertToAbsolutePath Condition="@(_NuspecFiles) != ''" Paths="@(_NuspecFiles)"> |
261 | 280 | <Output TaskParameter="AbsolutePaths" PropertyName="NuspecFileAbsolutePath" /> |
|
0 commit comments