Skip to content

Commit 52360b9

Browse files
committed
update paket.restore.targets
1 parent 9cedee0 commit 52360b9

File tree

1 file changed

+158
-17
lines changed

1 file changed

+158
-17
lines changed

.paket/Paket.Restore.targets

Lines changed: 158 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,101 @@
11
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
<!-- Prevent dotnet template engine to parse this file -->
3+
<!--/-:cnd:noEmit-->
24
<PropertyGroup>
5+
<!-- make MSBuild track this file for incremental builds. -->
6+
<!-- ref https://blogs.msdn.microsoft.com/msbuild/2005/09/26/how-to-ensure-changes-to-a-custom-target-file-prompt-a-rebuild/ -->
7+
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
38
<!-- Mark that this target file has been loaded. -->
49
<IsPaketRestoreTargetsFileLoaded>true</IsPaketRestoreTargetsFileLoaded>
510
<PaketToolsPath>$(MSBuildThisFileDirectory)</PaketToolsPath>
11+
<PaketRootPath>$(MSBuildThisFileDirectory)..\</PaketRootPath>
12+
<PaketRestoreCacheFile>$(PaketRootPath)paket-files\paket.restore.cached</PaketRestoreCacheFile>
13+
<PaketLockFilePath>$(PaketRootPath)paket.lock</PaketLockFilePath>
614
<MonoPath Condition="'$(MonoPath)' == '' And Exists('/Library/Frameworks/Mono.framework/Commands/mono')">/Library/Frameworks/Mono.framework/Commands/mono</MonoPath>
715
<MonoPath Condition="'$(MonoPath)' == ''">mono</MonoPath>
816
<!-- Paket command -->
917
<PaketExePath Condition=" '$(PaketExePath)' == '' AND Exists('$(PaketRootPath)paket.exe')">$(PaketRootPath)paket.exe</PaketExePath>
1018
<PaketExePath Condition=" '$(PaketExePath)' == '' ">$(PaketToolsPath)paket.exe</PaketExePath>
1119
<PaketCommand Condition=" '$(OS)' == 'Windows_NT'">"$(PaketExePath)"</PaketCommand>
1220
<PaketCommand Condition=" '$(OS)' != 'Windows_NT' ">$(MonoPath) --runtime=v4.0.30319 "$(PaketExePath)"</PaketCommand>
21+
<PaketBootStrapperExePath Condition=" '$(PaketBootStrapperExePath)' == '' AND Exists('$(PaketRootPath)paket.bootstrapper.exe')">$(PaketRootPath)paket.bootstrapper.exe</PaketBootStrapperExePath>
22+
<PaketBootStrapperExePath Condition=" '$(PaketBootStrapperExePath)' == '' ">$(PaketToolsPath)paket.bootstrapper.exe</PaketBootStrapperExePath>
23+
<PaketBootStrapperCommand Condition=" '$(OS)' == 'Windows_NT'">"$(PaketBootStrapperExePath)"</PaketBootStrapperCommand>
24+
<PaketBootStrapperCommand Condition=" '$(OS)' != 'Windows_NT' ">$(MonoPath) --runtime=v4.0.30319 "$(PaketBootStrapperExePath)"</PaketBootStrapperCommand>
25+
26+
<!-- Disable automagic references for F# dotnet sdk -->
27+
<!-- This will not do anything for other project types -->
28+
<!-- see https://github.com/fsharp/fslang-design/blob/master/RFCs/FS-1032-fsharp-in-dotnet-sdk.md -->
29+
<DisableImplicitFSharpCoreReference>true</DisableImplicitFSharpCoreReference>
30+
<DisableImplicitSystemValueTupleReference>true</DisableImplicitSystemValueTupleReference>
1331
</PropertyGroup>
1432

15-
<Target Name="PaketRestore" BeforeTargets="_GenerateProjectRestoreGraphPerFramework;_GenerateRestoreGraphWalkPerFramework;CollectPackageReferences" >
33+
<Target Name="PaketRestore" Condition="'$(PaketRestoreDisabled)' != 'True'" BeforeTargets="_GenerateDotnetCliToolReferenceSpecs;_GenerateProjectRestoreGraphPerFramework;_GenerateRestoreGraphWalkPerFramework;CollectPackageReferences" >
1634

17-
<Exec Command='$(PaketCommand) restore --project "$(MSBuildProjectFullPath)" ' />
35+
<!-- Step 1 Check if lockfile is properly restored -->
36+
<PropertyGroup>
37+
<PaketRestoreRequired>true</PaketRestoreRequired>
38+
<NoWarn>$(NoWarn);NU1603</NoWarn>
39+
</PropertyGroup>
40+
41+
<PropertyGroup Condition="Exists('$(PaketRestoreCacheFile)') ">
42+
<PaketRestoreCachedHash>$([System.IO.File]::ReadAllText('$(PaketRestoreCacheFile)'))</PaketRestoreCachedHash>
43+
<PaketRestoreLockFileHash>$([System.IO.File]::ReadAllText('$(PaketLockFilePath)'))</PaketRestoreLockFileHash>
44+
<PaketRestoreRequired>true</PaketRestoreRequired>
45+
<PaketRestoreRequired Condition=" '$(PaketRestoreLockFileHash)' == '$(PaketRestoreCachedHash)' ">false</PaketRestoreRequired>
46+
<PaketRestoreRequired Condition=" '$(PaketRestoreLockFileHash)' == '' ">true</PaketRestoreRequired>
47+
</PropertyGroup>
1848

49+
<!-- Do a global restore if required -->
50+
<Exec Command='$(PaketBootStrapperCommand)' Condition="Exists('$(PaketBootStrapperExePath)') AND !(Exists('$(PaketExePath)'))" ContinueOnError="false" />
51+
<Exec Command='$(PaketCommand) restore' Condition=" '$(PaketRestoreRequired)' == 'true' " ContinueOnError="false" />
52+
53+
<!-- Step 2 Detect project specific changes -->
1954
<PropertyGroup>
20-
<PaketReferencesFilePath>$(MSBuildProjectDirectory)/obj/$(MSBuildProjectFile).references</PaketReferencesFilePath>
55+
<PaketReferencesCachedFilePath>$(MSBuildProjectDirectory)\obj\$(MSBuildProjectFile).paket.references.cached</PaketReferencesCachedFilePath>
56+
<!-- MyProject.fsproj.paket.references has the highest precedence -->
57+
<PaketOriginalReferencesFilePath>$(MSBuildProjectFullPath).paket.references</PaketOriginalReferencesFilePath>
58+
<!-- MyProject.paket.references -->
59+
<PaketOriginalReferencesFilePath Condition=" !Exists('$(PaketOriginalReferencesFilePath)')">$(MSBuildProjectDirectory)\$(MSBuildProjectName).paket.references</PaketOriginalReferencesFilePath>
60+
<!-- paket.references -->
61+
<PaketOriginalReferencesFilePath Condition=" !Exists('$(PaketOriginalReferencesFilePath)')">$(MSBuildProjectDirectory)\paket.references</PaketOriginalReferencesFilePath>
62+
<PaketResolvedFilePath>$(MSBuildProjectDirectory)\obj\$(MSBuildProjectFile).$(TargetFramework).paket.resolved</PaketResolvedFilePath>
63+
<PaketRestoreRequired>true</PaketRestoreRequired>
64+
<PaketRestoreRequiredReason>references-file-or-cache-not-found</PaketRestoreRequiredReason>
65+
</PropertyGroup>
66+
67+
<!-- Step 2 a Detect changes in references file -->
68+
<PropertyGroup Condition="Exists('$(PaketOriginalReferencesFilePath)') AND Exists('$(PaketReferencesCachedFilePath)') ">
69+
<PaketRestoreCachedHash>$([System.IO.File]::ReadAllText('$(PaketReferencesCachedFilePath)'))</PaketRestoreCachedHash>
70+
<PaketRestoreReferencesFileHash>$([System.IO.File]::ReadAllText('$(PaketOriginalReferencesFilePath)'))</PaketRestoreReferencesFileHash>
71+
<PaketRestoreRequiredReason>references-file</PaketRestoreRequiredReason>
72+
<PaketRestoreRequired Condition=" '$(PaketRestoreReferencesFileHash)' == '$(PaketRestoreCachedHash)' ">false</PaketRestoreRequired>
2173
</PropertyGroup>
2274

23-
<ReadLinesFromFile File="$(PaketReferencesFilePath)" >
75+
<PropertyGroup Condition="!Exists('$(PaketOriginalReferencesFilePath)') AND !Exists('$(PaketReferencesCachedFilePath)') ">
76+
<!-- If both don't exist there is nothing to do. -->
77+
<PaketRestoreRequired>false</PaketRestoreRequired>
78+
</PropertyGroup>
79+
80+
<!-- Step 2 b detect relevant changes in project file (new targetframework) -->
81+
<PropertyGroup Condition=" !Exists('$(PaketResolvedFilePath)') AND '$(TargetFramework)' != '' ">
82+
<PaketRestoreRequired>true</PaketRestoreRequired>
83+
<PaketRestoreRequiredReason>target-framework '$(TargetFramework)'</PaketRestoreRequiredReason>
84+
</PropertyGroup>
85+
86+
<!-- Step 3 Restore project specific stuff if required -->
87+
<Message Condition=" '$(PaketRestoreRequired)' == 'true' " Importance="low" Text="Detected a change ('$(PaketRestoreRequiredReason)') in the project file '$(MSBuildProjectFullPath)', calling paket restore" />
88+
<Exec Command='$(PaketCommand) restore --project "$(MSBuildProjectFullPath)"' Condition=" '$(PaketRestoreRequired)' == 'true' " ContinueOnError="false" />
89+
90+
<!-- This shouldn't actually happen, but just to be sure. -->
91+
<Error Condition=" !Exists('$(PaketResolvedFilePath)') AND '$(TargetFramework)' != '' AND '$(ResolveNuGetPackages)' != 'False' " Text="Paket file '$(PaketResolvedFilePath)' is missing while restoring $(MSBuildProjectFile). Please delete 'paket-files/paket.restore.cached' and call 'paket restore'." />
92+
93+
<!-- Step 4 forward all msbuild properties (PackageReference, DotNetCliToolReference) to msbuild -->
94+
<ReadLinesFromFile Condition="Exists('$(PaketResolvedFilePath)')" File="$(PaketResolvedFilePath)" >
2495
<Output TaskParameter="Lines" ItemName="PaketReferencesFileLines"/>
2596
</ReadLinesFromFile>
2697

27-
<ItemGroup Condition=" '@(PaketReferencesFileLines)' != '' " >
98+
<ItemGroup Condition=" Exists('$(PaketResolvedFilePath)') AND '@(PaketReferencesFileLines)' != '' " >
2899
<PaketReferencesFileLinesInfo Include="@(PaketReferencesFileLines)" >
29100
<PackageName>$([System.String]::Copy('%(PaketReferencesFileLines.Identity)').Split(',')[0])</PackageName>
30101
<PackageVersion>$([System.String]::Copy('%(PaketReferencesFileLines.Identity)').Split(',')[1])</PackageVersion>
@@ -34,36 +105,106 @@
34105
</PackageReference>
35106
</ItemGroup>
36107

108+
<PropertyGroup>
109+
<PaketCliToolFilePath>$(MSBuildProjectDirectory)/obj/$(MSBuildProjectFile).paket.clitools</PaketCliToolFilePath>
110+
</PropertyGroup>
111+
112+
<ReadLinesFromFile File="$(PaketCliToolFilePath)" >
113+
<Output TaskParameter="Lines" ItemName="PaketCliToolFileLines"/>
114+
</ReadLinesFromFile>
115+
116+
<ItemGroup Condition=" '@(PaketCliToolFileLines)' != '' " >
117+
<PaketCliToolFileLinesInfo Include="@(PaketCliToolFileLines)" >
118+
<PackageName>$([System.String]::Copy('%(PaketCliToolFileLines.Identity)').Split(',')[0])</PackageName>
119+
<PackageVersion>$([System.String]::Copy('%(PaketCliToolFileLines.Identity)').Split(',')[1])</PackageVersion>
120+
</PaketCliToolFileLinesInfo>
121+
<DotNetCliToolReference Include="%(PaketCliToolFileLinesInfo.PackageName)">
122+
<Version>%(PaketCliToolFileLinesInfo.PackageVersion)</Version>
123+
</DotNetCliToolReference>
124+
</ItemGroup>
125+
37126
<PropertyGroup>
38127
<RestoreConfigFile>$(MSBuildProjectDirectory)/obj/$(MSBuildProjectFile).NuGet.Config</RestoreConfigFile>
39128
</PropertyGroup>
40129

41130
</Target>
42131

43-
<Target Name="PaketDisableDirectPack" AfterTargets="_IntermediatePack" BeforeTargets="GenerateNuspec" >
132+
<Target Name="PaketDisableDirectPack" AfterTargets="_IntermediatePack" BeforeTargets="GenerateNuspec" Condition="('$(IsPackable)' == '' Or '$(IsPackable)' == 'true') And Exists('$(MSBuildProjectDirectory)/obj/$(MSBuildProjectFile).references')" >
44133
<PropertyGroup>
45134
<ContinuePackingAfterGeneratingNuspec>false</ContinuePackingAfterGeneratingNuspec>
46135
</PropertyGroup>
47136
</Target>
48-
49-
<Target Name="PaketOverrideNuspec" AfterTargets="GenerateNuspec" >
137+
138+
<Target Name="PaketOverrideNuspec" AfterTargets="GenerateNuspec" Condition="('$(IsPackable)' == '' Or '$(IsPackable)' == 'true') And Exists('$(MSBuildProjectDirectory)/obj/$(MSBuildProjectFile).references')" >
139+
<ItemGroup>
140+
<_NuspecFilesNewLocation Include="$(BaseIntermediateOutputPath)$(Configuration)/*.nuspec"/>
141+
</ItemGroup>
142+
50143
<PropertyGroup>
51-
<PaketReferencesFilePath>$(MSBuildProjectDirectory)/obj/$(MSBuildProjectFile).references</PaketReferencesFilePath>
144+
<PaketProjectFile>$(MSBuildProjectDirectory)/$(MSBuildProjectFile)</PaketProjectFile>
52145
<ContinuePackingAfterGeneratingNuspec>true</ContinuePackingAfterGeneratingNuspec>
146+
<UseNewPack>false</UseNewPack>
147+
<UseNewPack Condition=" '$(NuGetToolVersion)' != '4.0.0' ">true</UseNewPack>
148+
<AdjustedNuspecOutputPath>$(BaseIntermediateOutputPath)$(Configuration)/</AdjustedNuspecOutputPath>
149+
<AdjustedNuspecOutputPath Condition="@(_NuspecFilesNewLocation) == ''">$(BaseIntermediateOutputPath)</AdjustedNuspecOutputPath>
53150
</PropertyGroup>
54151

55152
<ItemGroup>
56-
<_NuspecFiles Include="$(BaseIntermediateOutputPath)*.nuspec"/>
153+
<_NuspecFiles Include="$(AdjustedNuspecOutputPath)*.nuspec"/>
57154
</ItemGroup>
58155

59-
<Exec Command='$(PaketCommand) fix-nuspec file "@(_NuspecFiles)" references-file "$(PaketReferencesFilePath)" ' />
60-
156+
<Exec Command='$(PaketCommand) fix-nuspecs files "@(_NuspecFiles)" project-file "$(PaketProjectFile)" ' Condition="@(_NuspecFiles) != ''" />
157+
61158
<ConvertToAbsolutePath Condition="@(_NuspecFiles) != ''" Paths="@(_NuspecFiles)">
62159
<Output TaskParameter="AbsolutePaths" PropertyName="NuspecFileAbsolutePath" />
63160
</ConvertToAbsolutePath>
64-
161+
65162
<!-- Call Pack -->
66-
<PackTask PackItem="$(PackProjectInputFile)"
163+
<PackTask Condition="$(UseNewPack)"
164+
PackItem="$(PackProjectInputFile)"
165+
PackageFiles="@(_PackageFiles)"
166+
PackageFilesToExclude="@(_PackageFilesToExclude)"
167+
PackageVersion="$(PackageVersion)"
168+
PackageId="$(PackageId)"
169+
Title="$(Title)"
170+
Authors="$(Authors)"
171+
Description="$(Description)"
172+
Copyright="$(Copyright)"
173+
RequireLicenseAcceptance="$(PackageRequireLicenseAcceptance)"
174+
LicenseUrl="$(PackageLicenseUrl)"
175+
ProjectUrl="$(PackageProjectUrl)"
176+
IconUrl="$(PackageIconUrl)"
177+
ReleaseNotes="$(PackageReleaseNotes)"
178+
Tags="$(PackageTags)"
179+
DevelopmentDependency="$(DevelopmentDependency)"
180+
BuildOutputInPackage="@(_BuildOutputInPackage)"
181+
TargetPathsToSymbols="@(_TargetPathsToSymbols)"
182+
TargetFrameworks="@(_TargetFrameworks)"
183+
AssemblyName="$(AssemblyName)"
184+
PackageOutputPath="$(PackageOutputAbsolutePath)"
185+
IncludeSymbols="$(IncludeSymbols)"
186+
IncludeSource="$(IncludeSource)"
187+
PackageTypes="$(PackageType)"
188+
IsTool="$(IsTool)"
189+
RepositoryUrl="$(RepositoryUrl)"
190+
RepositoryType="$(RepositoryType)"
191+
SourceFiles="@(_SourceFiles->Distinct())"
192+
NoPackageAnalysis="$(NoPackageAnalysis)"
193+
MinClientVersion="$(MinClientVersion)"
194+
Serviceable="$(Serviceable)"
195+
FrameworkAssemblyReferences="@(_FrameworkAssemblyReferences)"
196+
ContinuePackingAfterGeneratingNuspec="$(ContinuePackingAfterGeneratingNuspec)"
197+
NuspecOutputPath="$(AdjustedNuspecOutputPath)"
198+
IncludeBuildOutput="$(IncludeBuildOutput)"
199+
BuildOutputFolder="$(BuildOutputTargetFolder)"
200+
ContentTargetFolders="$(ContentTargetFolders)"
201+
RestoreOutputPath="$(RestoreOutputAbsolutePath)"
202+
NuspecFile="$(NuspecFileAbsolutePath)"
203+
NuspecBasePath="$(NuspecBasePath)"
204+
NuspecProperties="$(NuspecProperties)"/>
205+
206+
<PackTask Condition="! $(UseNewPack)"
207+
PackItem="$(PackProjectInputFile)"
67208
PackageFiles="@(_PackageFiles)"
68209
PackageFilesToExclude="@(_PackageFilesToExclude)"
69210
PackageVersion="$(PackageVersion)"
@@ -95,7 +236,7 @@
95236
Serviceable="$(Serviceable)"
96237
AssemblyReferences="@(_References)"
97238
ContinuePackingAfterGeneratingNuspec="$(ContinuePackingAfterGeneratingNuspec)"
98-
NuspecOutputPath="$(BaseIntermediateOutputPath)"
239+
NuspecOutputPath="$(AdjustedNuspecOutputPath)"
99240
IncludeBuildOutput="$(IncludeBuildOutput)"
100241
BuildOutputFolder="$(BuildOutputTargetFolder)"
101242
ContentTargetFolders="$(ContentTargetFolders)"
@@ -104,5 +245,5 @@
104245
NuspecBasePath="$(NuspecBasePath)"
105246
NuspecProperties="$(NuspecProperties)"/>
106247
</Target>
107-
108-
</Project>
248+
<!--/+:cnd:noEmit-->
249+
</Project>

0 commit comments

Comments
 (0)