-
Notifications
You must be signed in to change notification settings - Fork 119
Expand file tree
/
Copy pathDirectory.Build.targets
More file actions
159 lines (142 loc) · 6.15 KB
/
Copy pathDirectory.Build.targets
File metadata and controls
159 lines (142 loc) · 6.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<Project>
<PropertyGroup>
<ReqnrollCompatibilityVersionRange>[$(PackageVersion),$(CompatibilityVersionUpperRange))</ReqnrollCompatibilityVersionRange>
<PackagesOutputPath>$(MSBuildThisFileDirectory)GeneratedNuGetPackages\$(Configuration)</PackagesOutputPath>
</PropertyGroup>
<!-- Copies generated NuGet packages and symbol packages to the output packages path -->
<Target
Name="CopyPackageToPackagesOutputPath"
AfterTargets="Pack">
<ItemGroup>
<GeneratedPackages Include="$(PackageOutputAbsolutePath)\*$(Version).*nupkg"/>
</ItemGroup>
<Copy SourceFiles="@(GeneratedPackages)" DestinationFolder="$(PackagesOutputPath)" />
</Target>
<UsingTask
TaskName="ReqnrollClearNuGetCache"
TaskFactory="RoslynCodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll" >
<ParameterGroup>
<NuGetCacheDirectory ParameterType="System.String" Required="true" />
<EnsureNugetCacheCleared ParameterType="System.String" />
</ParameterGroup>
<Task>
<Using Namespace="System"/>
<Using Namespace="System.IO"/>
<Code Type="Fragment" Language="cs">
<![CDATA[
string TmpDirectory = NuGetCacheDirectory + "-remove";
Log.LogMessage("Cleaning local nuget cache " + NuGetCacheDirectory);
if (Directory.Exists(TmpDirectory))
{
try
{
Directory.Delete(TmpDirectory, true);
}
catch
{
Log.LogError("Can't start cleaning NuGet Cache Directory, deleting temporary directory failed: " + NuGetCacheDirectory);
}
}
if (Directory.Exists(NuGetCacheDirectory))
{
try
{
// If a file is locked, calling Directory.Delete can result in half-removed directories.
// This is bad for nuget caches, as dotnet restore may fail in these cases.
// That's why we first move the directory (which is only possible if no file is locked in the directory) and then delete the renamed directory.
Directory.Move(NuGetCacheDirectory, TmpDirectory);
}
catch (Exception ex)
{
if (EnsureNugetCacheCleared != "false")
Log.LogError("Can't clean NuGet Cache Directory " + NuGetCacheDirectory + ". Set REQNROLL_ENSURE_NUGET_CACHE_CLEARED to false to handle this error as a warning. " + ex.Message);
else
Log.LogWarning("Can't clean NuGet Cache Directory " + NuGetCacheDirectory);
}
}
if (Directory.Exists(TmpDirectory))
{
try
{
Directory.Delete(TmpDirectory, true);
}
catch
{
Log.LogWarning("Can't finish cleaning NuGet Cache Directory, deleting temporary directory failed: " + NuGetCacheDirectory);
}
}
]]>
</Code>
</Task>
</UsingTask>
<Target Name="DeleteLocalNuGetCache" BeforeTargets="Pack" Condition="$(VersionSuffix)=='local'">
<!--Clears the NuGet cache manually until https://github.com/NuGet/Home/issues/5713 is fixed.-->
<!--Implementation based on https://www.nyckel.com/blog/nuget-packages/.-->
<ReqnrollClearNuGetCache NuGetCacheDirectory="$(NugetPackageRoot)/$(PackageId.ToLower())/$(VersionPrefix)-$(VersionSuffix)" EnsureNugetCacheCleared="$(REQNROLL_ENSURE_NUGET_CACHE_CLEARED)"/>
</Target>
<!-- Get the list of project reference outputs that should be packed as part of this package. -->
<Target
Name="_GetProjectReferenceCopyLocalPathsForPackAsComponent"
DependsOnTargets="ResolveReferences"
Returns="_ProjectReferenceCopyLocalPathsForPackAsComponent">
<ItemGroup>
<_ReferenceCopyLocalProjects
Include="@(ReferenceCopyLocalPaths -> '%(ProjectReferenceOriginalItemSpec)')"
Condition="'%(ReferenceCopyLocalPaths.ReferenceSourceTarget)' == 'ProjectReference' AND '%(ReferenceCopyLocalPaths.PackAsComponent)' == 'true'">
<Asset>%(Identity)</Asset>
</_ReferenceCopyLocalProjects>
</ItemGroup>
<ItemGroup>
<_ProjectReferenceCopyLocalPathsForPackAsComponent
Include="@(_ReferenceCopyLocalProjects->'%(Asset)')"
Condition="'%(ProjectReference.PackAsComponent)' == 'true'"/>
</ItemGroup>
</Target>
<PropertyGroup>
<TargetsForTfmSpecificContentInPackage>
$(TargetsForTfmSpecificContentInPackage);
CollectProjectReferenceOutputsForPack
</TargetsForTfmSpecificContentInPackage>
<CollectProjectReferenceOutputsForPackDependsOn>
$(CollectProjectReferenceOutputsForPackDependsOn);
_GetProjectReferenceCopyLocalPathsForPackAsComponent
</CollectProjectReferenceOutputsForPackDependsOn>
</PropertyGroup>
<!-- Include referenced project assembly as part of this package directly. -->
<Target Name="CollectProjectReferenceOutputsForPack" DependsOnTargets="$(CollectProjectReferenceOutputsForPackDependsOn)">
<ItemGroup>
<TfmSpecificPackageFile
Include="@(_ProjectReferenceCopyLocalPathsForPackAsComponent)"
PackagePath="lib/$(TargetFramework)/"
Condition="'%(Extension)' != '.pdb'"/>
</ItemGroup>
</Target>
<PropertyGroup>
<TargetsForTfmSpecificDebugSymbolsInPackage>
$(TargetsForTfmSpecificDebugSymbolsInPackage);
CollectProjectReferenceDebugSymbolsForPack
</TargetsForTfmSpecificDebugSymbolsInPackage>
<CollectProjectReferenceDebugSymbolsForPackDependsOn>
$(CollectProjectReferenceDebugSymbolsForPackDependsOn);
_GetProjectReferenceCopyLocalPathsForPackAsComponent
</CollectProjectReferenceDebugSymbolsForPackDependsOn>
</PropertyGroup>
<!-- Included referenced project PDBs as part of the symbols package. -->
<Target Name="CollectProjectReferenceDebugSymbolsForPack" DependsOnTargets="$(CollectProjectReferenceDebugSymbolsForPackDependsOn)">
<ItemGroup>
<TfmSpecificDebugSymbolsFile
Include="@(_ProjectReferenceCopyLocalPathsForPackAsComponent)"
Condition="'%(Extension)' == '.pdb'"/>
</ItemGroup>
<ItemGroup>
<_TfmSpecificDebugSymbolsCandidate
Include="@(_ProjectReferenceCopyLocalPathsForPackAsComponent->'%(RootDir)%(Directory)%(Filename).pdb')"
Condition="'%(Extension)' != '.pdb'"/>
<TfmSpecificDebugSymbolsFile
Include="@(_TfmSpecificDebugSymbolsCandidate)"
TargetFramework="$(TargetFramework)"
Condition="Exists('%(FullPath)')" />
</ItemGroup>
</Target>
</Project>