Skip to content

Commit 0e0500a

Browse files
committed
added per paket author comment:
> Better commit it for proper VS support fsprojects/Paket#2840 (comment)
1 parent 33ce7b9 commit 0e0500a

File tree

1 file changed

+265
-0
lines changed

1 file changed

+265
-0
lines changed

.paket/Paket.Restore.targets

Lines changed: 265 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,265 @@
1+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
<!-- Prevent dotnet template engine to parse this file -->
3+
<!--/-:cnd:noEmit-->
4+
<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>
8+
<!-- Mark that this target file has been loaded. -->
9+
<IsPaketRestoreTargetsFileLoaded>true</IsPaketRestoreTargetsFileLoaded>
10+
<PaketToolsPath>$(MSBuildThisFileDirectory)</PaketToolsPath>
11+
<PaketRootPath>$(MSBuildThisFileDirectory)..\</PaketRootPath>
12+
<PaketRestoreCacheFile>$(PaketRootPath)paket-files\paket.restore.cached</PaketRestoreCacheFile>
13+
<PaketLockFilePath>$(PaketRootPath)paket.lock</PaketLockFilePath>
14+
<MonoPath Condition="'$(MonoPath)' == '' And Exists('/Library/Frameworks/Mono.framework/Commands/mono')">/Library/Frameworks/Mono.framework/Commands/mono</MonoPath>
15+
<MonoPath Condition="'$(MonoPath)' == ''">mono</MonoPath>
16+
<!-- Paket command -->
17+
<PaketExePath Condition=" '$(PaketExePath)' == '' AND Exists('$(PaketRootPath)paket.exe')">$(PaketRootPath)paket.exe</PaketExePath>
18+
<PaketExePath Condition=" '$(PaketExePath)' == '' ">$(PaketToolsPath)paket.exe</PaketExePath>
19+
<PaketCommand Condition=" '$(OS)' == 'Windows_NT'">"$(PaketExePath)"</PaketCommand>
20+
<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>
31+
</PropertyGroup>
32+
33+
<Target Name="PaketRestore" Condition="'$(PaketRestoreDisabled)' != 'True'" BeforeTargets="_GenerateDotnetCliToolReferenceSpecs;_GenerateProjectRestoreGraphPerFramework;_GenerateRestoreGraphWalkPerFramework;CollectPackageReferences" >
34+
35+
<!-- Step 1 Check if lockfile is properly restored -->
36+
<PropertyGroup>
37+
<PaketRestoreRequired>true</PaketRestoreRequired>
38+
<NoWarn>$(NoWarn);NU1603</NoWarn>
39+
</PropertyGroup>
40+
41+
<!-- Because ReadAllText is slow on osx/linux, try to find shasum and awk -->
42+
<PropertyGroup>
43+
<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>
44+
<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>
45+
</PropertyGroup>
46+
47+
<!-- If shasum and awk exist get the hashes -->
48+
<Exec Condition=" '$(PaketRestoreCachedHasher)' != '' " Command="$(PaketRestoreCachedHasher)" ConsoleToMSBuild='true'>
49+
<Output TaskParameter="ConsoleOutput" PropertyName="PaketRestoreCachedHash" />
50+
</Exec>
51+
<Exec Condition=" '$(PaketRestoreLockFileHasher)' != '' " Command="$(PaketRestoreLockFileHasher)" ConsoleToMSBuild='true'>
52+
<Output TaskParameter="ConsoleOutput" PropertyName="PaketRestoreLockFileHash" />
53+
</Exec>
54+
55+
<PropertyGroup Condition="Exists('$(PaketRestoreCacheFile)') ">
56+
<!-- if no hash has been done yet fall back to just reading in the files and comparing them -->
57+
<PaketRestoreCachedHash Condition=" '$(PaketRestoreCachedHash)' == '' ">$([System.IO.File]::ReadAllText('$(PaketRestoreCacheFile)'))</PaketRestoreCachedHash>
58+
<PaketRestoreLockFileHash Condition=" '$(PaketRestoreLockFileHash)' == '' ">$([System.IO.File]::ReadAllText('$(PaketLockFilePath)'))</PaketRestoreLockFileHash>
59+
<PaketRestoreRequired>true</PaketRestoreRequired>
60+
<PaketRestoreRequired Condition=" '$(PaketRestoreLockFileHash)' == '$(PaketRestoreCachedHash)' ">false</PaketRestoreRequired>
61+
<PaketRestoreRequired Condition=" '$(PaketRestoreLockFileHash)' == '' ">true</PaketRestoreRequired>
62+
</PropertyGroup>
63+
64+
<!-- Do a global restore if required -->
65+
<Exec Command='$(PaketBootStrapperCommand)' Condition="Exists('$(PaketBootStrapperExePath)') AND !(Exists('$(PaketExePath)'))" ContinueOnError="false" />
66+
<Exec Command='$(PaketCommand) restore' Condition=" '$(PaketRestoreRequired)' == 'true' " ContinueOnError="false" />
67+
68+
<!-- Step 2 Detect project specific changes -->
69+
<PropertyGroup>
70+
<PaketReferencesCachedFilePath>$(MSBuildProjectDirectory)\obj\$(MSBuildProjectFile).paket.references.cached</PaketReferencesCachedFilePath>
71+
<!-- MyProject.fsproj.paket.references has the highest precedence -->
72+
<PaketOriginalReferencesFilePath>$(MSBuildProjectFullPath).paket.references</PaketOriginalReferencesFilePath>
73+
<!-- MyProject.paket.references -->
74+
<PaketOriginalReferencesFilePath Condition=" !Exists('$(PaketOriginalReferencesFilePath)')">$(MSBuildProjectDirectory)\$(MSBuildProjectName).paket.references</PaketOriginalReferencesFilePath>
75+
<!-- paket.references -->
76+
<PaketOriginalReferencesFilePath Condition=" !Exists('$(PaketOriginalReferencesFilePath)')">$(MSBuildProjectDirectory)\paket.references</PaketOriginalReferencesFilePath>
77+
<PaketResolvedFilePath>$(MSBuildProjectDirectory)\obj\$(MSBuildProjectFile).$(TargetFramework).paket.resolved</PaketResolvedFilePath>
78+
<PaketRestoreRequired>true</PaketRestoreRequired>
79+
<PaketRestoreRequiredReason>references-file-or-cache-not-found</PaketRestoreRequiredReason>
80+
</PropertyGroup>
81+
82+
<!-- Step 2 a Detect changes in references file -->
83+
<PropertyGroup Condition="Exists('$(PaketOriginalReferencesFilePath)') AND Exists('$(PaketReferencesCachedFilePath)') ">
84+
<PaketRestoreCachedHash>$([System.IO.File]::ReadAllText('$(PaketReferencesCachedFilePath)'))</PaketRestoreCachedHash>
85+
<PaketRestoreReferencesFileHash>$([System.IO.File]::ReadAllText('$(PaketOriginalReferencesFilePath)'))</PaketRestoreReferencesFileHash>
86+
<PaketRestoreRequiredReason>references-file</PaketRestoreRequiredReason>
87+
<PaketRestoreRequired Condition=" '$(PaketRestoreReferencesFileHash)' == '$(PaketRestoreCachedHash)' ">false</PaketRestoreRequired>
88+
</PropertyGroup>
89+
90+
<PropertyGroup Condition="!Exists('$(PaketOriginalReferencesFilePath)') AND !Exists('$(PaketReferencesCachedFilePath)') ">
91+
<!-- If both don't exist there is nothing to do. -->
92+
<PaketRestoreRequired>false</PaketRestoreRequired>
93+
</PropertyGroup>
94+
95+
<!-- Step 2 b detect relevant changes in project file (new targetframework) -->
96+
<PropertyGroup Condition=" !Exists('$(PaketResolvedFilePath)') AND '$(TargetFramework)' != '' ">
97+
<PaketRestoreRequired>true</PaketRestoreRequired>
98+
<PaketRestoreRequiredReason>target-framework '$(TargetFramework)'</PaketRestoreRequiredReason>
99+
</PropertyGroup>
100+
101+
<!-- Step 3 Restore project specific stuff if required -->
102+
<Message Condition=" '$(PaketRestoreRequired)' == 'true' " Importance="low" Text="Detected a change ('$(PaketRestoreRequiredReason)') in the project file '$(MSBuildProjectFullPath)', calling paket restore" />
103+
<Exec Command='$(PaketCommand) restore --project "$(MSBuildProjectFullPath)"' Condition=" '$(PaketRestoreRequired)' == 'true' " ContinueOnError="false" />
104+
105+
<!-- This shouldn't actually happen, but just to be sure. -->
106+
<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'." />
107+
108+
<!-- Step 4 forward all msbuild properties (PackageReference, DotNetCliToolReference) to msbuild -->
109+
<ReadLinesFromFile Condition="Exists('$(PaketResolvedFilePath)')" File="$(PaketResolvedFilePath)" >
110+
<Output TaskParameter="Lines" ItemName="PaketReferencesFileLines"/>
111+
</ReadLinesFromFile>
112+
113+
<ItemGroup Condition=" Exists('$(PaketResolvedFilePath)') AND '@(PaketReferencesFileLines)' != '' " >
114+
<PaketReferencesFileLinesInfo Include="@(PaketReferencesFileLines)" >
115+
<PackageName>$([System.String]::Copy('%(PaketReferencesFileLines.Identity)').Split(',')[0])</PackageName>
116+
<PackageVersion>$([System.String]::Copy('%(PaketReferencesFileLines.Identity)').Split(',')[1])</PackageVersion>
117+
</PaketReferencesFileLinesInfo>
118+
<PackageReference Include="%(PaketReferencesFileLinesInfo.PackageName)">
119+
<Version>%(PaketReferencesFileLinesInfo.PackageVersion)</Version>
120+
</PackageReference>
121+
</ItemGroup>
122+
123+
<PropertyGroup>
124+
<PaketCliToolFilePath>$(MSBuildProjectDirectory)/obj/$(MSBuildProjectFile).paket.clitools</PaketCliToolFilePath>
125+
</PropertyGroup>
126+
127+
<ReadLinesFromFile File="$(PaketCliToolFilePath)" >
128+
<Output TaskParameter="Lines" ItemName="PaketCliToolFileLines"/>
129+
</ReadLinesFromFile>
130+
131+
<ItemGroup Condition=" '@(PaketCliToolFileLines)' != '' " >
132+
<PaketCliToolFileLinesInfo Include="@(PaketCliToolFileLines)" >
133+
<PackageName>$([System.String]::Copy('%(PaketCliToolFileLines.Identity)').Split(',')[0])</PackageName>
134+
<PackageVersion>$([System.String]::Copy('%(PaketCliToolFileLines.Identity)').Split(',')[1])</PackageVersion>
135+
</PaketCliToolFileLinesInfo>
136+
<DotNetCliToolReference Include="%(PaketCliToolFileLinesInfo.PackageName)">
137+
<Version>%(PaketCliToolFileLinesInfo.PackageVersion)</Version>
138+
</DotNetCliToolReference>
139+
</ItemGroup>
140+
141+
<PropertyGroup>
142+
<RestoreConfigFile>$(MSBuildProjectDirectory)/obj/$(MSBuildProjectFile).NuGet.Config</RestoreConfigFile>
143+
</PropertyGroup>
144+
145+
</Target>
146+
147+
<Target Name="PaketDisableDirectPack" AfterTargets="_IntermediatePack" BeforeTargets="GenerateNuspec" Condition="('$(IsPackable)' == '' Or '$(IsPackable)' == 'true') And Exists('$(MSBuildProjectDirectory)/obj/$(MSBuildProjectFile).references')" >
148+
<PropertyGroup>
149+
<ContinuePackingAfterGeneratingNuspec>false</ContinuePackingAfterGeneratingNuspec>
150+
</PropertyGroup>
151+
</Target>
152+
153+
<Target Name="PaketOverrideNuspec" AfterTargets="GenerateNuspec" Condition="('$(IsPackable)' == '' Or '$(IsPackable)' == 'true') And Exists('$(MSBuildProjectDirectory)/obj/$(MSBuildProjectFile).references')" >
154+
<ItemGroup>
155+
<_NuspecFilesNewLocation Include="$(BaseIntermediateOutputPath)$(Configuration)\*.nuspec"/>
156+
</ItemGroup>
157+
158+
<PropertyGroup>
159+
<PaketProjectFile>$(MSBuildProjectDirectory)/$(MSBuildProjectFile)</PaketProjectFile>
160+
<ContinuePackingAfterGeneratingNuspec>true</ContinuePackingAfterGeneratingNuspec>
161+
<UseNewPack>false</UseNewPack>
162+
<UseNewPack Condition=" '$(NuGetToolVersion)' != '4.0.0' ">true</UseNewPack>
163+
<AdjustedNuspecOutputPath>$(BaseIntermediateOutputPath)$(Configuration)</AdjustedNuspecOutputPath>
164+
<AdjustedNuspecOutputPath Condition="@(_NuspecFilesNewLocation) == ''">$(BaseIntermediateOutputPath)</AdjustedNuspecOutputPath>
165+
</PropertyGroup>
166+
167+
<ItemGroup>
168+
<_NuspecFiles Include="$(AdjustedNuspecOutputPath)\*.nuspec"/>
169+
</ItemGroup>
170+
171+
<Exec Command='$(PaketCommand) fix-nuspecs files "@(_NuspecFiles)" project-file "$(PaketProjectFile)" ' Condition="@(_NuspecFiles) != ''" />
172+
173+
<ConvertToAbsolutePath Condition="@(_NuspecFiles) != ''" Paths="@(_NuspecFiles)">
174+
<Output TaskParameter="AbsolutePaths" PropertyName="NuspecFileAbsolutePath" />
175+
</ConvertToAbsolutePath>
176+
177+
178+
<!-- Call Pack -->
179+
<PackTask Condition="$(UseNewPack)"
180+
PackItem="$(PackProjectInputFile)"
181+
PackageFiles="@(_PackageFiles)"
182+
PackageFilesToExclude="@(_PackageFilesToExclude)"
183+
PackageVersion="$(PackageVersion)"
184+
PackageId="$(PackageId)"
185+
Title="$(Title)"
186+
Authors="$(Authors)"
187+
Description="$(Description)"
188+
Copyright="$(Copyright)"
189+
RequireLicenseAcceptance="$(PackageRequireLicenseAcceptance)"
190+
LicenseUrl="$(PackageLicenseUrl)"
191+
ProjectUrl="$(PackageProjectUrl)"
192+
IconUrl="$(PackageIconUrl)"
193+
ReleaseNotes="$(PackageReleaseNotes)"
194+
Tags="$(PackageTags)"
195+
DevelopmentDependency="$(DevelopmentDependency)"
196+
BuildOutputInPackage="@(_BuildOutputInPackage)"
197+
TargetPathsToSymbols="@(_TargetPathsToSymbols)"
198+
TargetFrameworks="@(_TargetFrameworks)"
199+
AssemblyName="$(AssemblyName)"
200+
PackageOutputPath="$(PackageOutputAbsolutePath)"
201+
IncludeSymbols="$(IncludeSymbols)"
202+
IncludeSource="$(IncludeSource)"
203+
PackageTypes="$(PackageType)"
204+
IsTool="$(IsTool)"
205+
RepositoryUrl="$(RepositoryUrl)"
206+
RepositoryType="$(RepositoryType)"
207+
SourceFiles="@(_SourceFiles->Distinct())"
208+
NoPackageAnalysis="$(NoPackageAnalysis)"
209+
MinClientVersion="$(MinClientVersion)"
210+
Serviceable="$(Serviceable)"
211+
FrameworkAssemblyReferences="@(_FrameworkAssemblyReferences)"
212+
ContinuePackingAfterGeneratingNuspec="$(ContinuePackingAfterGeneratingNuspec)"
213+
NuspecOutputPath="$(AdjustedNuspecOutputPath)"
214+
IncludeBuildOutput="$(IncludeBuildOutput)"
215+
BuildOutputFolder="$(BuildOutputTargetFolder)"
216+
ContentTargetFolders="$(ContentTargetFolders)"
217+
RestoreOutputPath="$(RestoreOutputAbsolutePath)"
218+
NuspecFile="$(NuspecFileAbsolutePath)"
219+
NuspecBasePath="$(NuspecBasePath)"
220+
NuspecProperties="$(NuspecProperties)"/>
221+
222+
<PackTask Condition="! $(UseNewPack)"
223+
PackItem="$(PackProjectInputFile)"
224+
PackageFiles="@(_PackageFiles)"
225+
PackageFilesToExclude="@(_PackageFilesToExclude)"
226+
PackageVersion="$(PackageVersion)"
227+
PackageId="$(PackageId)"
228+
Title="$(Title)"
229+
Authors="$(Authors)"
230+
Description="$(Description)"
231+
Copyright="$(Copyright)"
232+
RequireLicenseAcceptance="$(PackageRequireLicenseAcceptance)"
233+
LicenseUrl="$(PackageLicenseUrl)"
234+
ProjectUrl="$(PackageProjectUrl)"
235+
IconUrl="$(PackageIconUrl)"
236+
ReleaseNotes="$(PackageReleaseNotes)"
237+
Tags="$(PackageTags)"
238+
TargetPathsToAssemblies="@(_TargetPathsToAssemblies->'%(FinalOutputPath)')"
239+
TargetPathsToSymbols="@(_TargetPathsToSymbols)"
240+
TargetFrameworks="@(_TargetFrameworks)"
241+
AssemblyName="$(AssemblyName)"
242+
PackageOutputPath="$(PackageOutputAbsolutePath)"
243+
IncludeSymbols="$(IncludeSymbols)"
244+
IncludeSource="$(IncludeSource)"
245+
PackageTypes="$(PackageType)"
246+
IsTool="$(IsTool)"
247+
RepositoryUrl="$(RepositoryUrl)"
248+
RepositoryType="$(RepositoryType)"
249+
SourceFiles="@(_SourceFiles->Distinct())"
250+
NoPackageAnalysis="$(NoPackageAnalysis)"
251+
MinClientVersion="$(MinClientVersion)"
252+
Serviceable="$(Serviceable)"
253+
AssemblyReferences="@(_References)"
254+
ContinuePackingAfterGeneratingNuspec="$(ContinuePackingAfterGeneratingNuspec)"
255+
NuspecOutputPath="$(AdjustedNuspecOutputPath)"
256+
IncludeBuildOutput="$(IncludeBuildOutput)"
257+
BuildOutputFolder="$(BuildOutputTargetFolder)"
258+
ContentTargetFolders="$(ContentTargetFolders)"
259+
RestoreOutputPath="$(RestoreOutputAbsolutePath)"
260+
NuspecFile="$(NuspecFileAbsolutePath)"
261+
NuspecBasePath="$(NuspecBasePath)"
262+
NuspecProperties="$(NuspecProperties)"/>
263+
</Target>
264+
<!--/+:cnd:noEmit-->
265+
</Project>

0 commit comments

Comments
 (0)