forked from reqnroll/Reqnroll
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDirectory.Build.targets
More file actions
84 lines (78 loc) · 3.12 KB
/
Copy pathDirectory.Build.targets
File metadata and controls
84 lines (78 loc) · 3.12 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
<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)\*.*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>
</Project>