-
Notifications
You must be signed in to change notification settings - Fork 46
/
Directory.Build.targets
100 lines (93 loc) · 4.28 KB
/
Directory.Build.targets
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
<Project>
<Target Name="SetNuspecProperties" BeforeTargets="GenerateNuspec">
<PropertyGroup>
<NuspecProperties>$(NuspecProperties);config=$(Configuration)</NuspecProperties>
<NuspecProperties>$(NuspecProperties);version=$(PackageVersion)</NuspecProperties>
<NuspecProperties>$(NuspecProperties);SolutionDir=$(MSBuildThisFileDirectory)</NuspecProperties>
<NuspecProperties>$(NuspecProperties);copyright=$(Reqnroll_Copyright)</NuspecProperties>
<NuspecProperties>$(NuspecProperties);author=$(Reqnroll_Authors)</NuspecProperties>
<NuspecProperties>$(NuspecProperties);owner=$(Reqnroll_Owners)</NuspecProperties>
<NuspecProperties>$(NuspecProperties);summary=$(Reqnroll_Summary)</NuspecProperties>
<NuspecProperties>$(NuspecProperties);CompatibilityVersionRange=[$(PackageVersion),$(CompatibilityVersionUpperRange))</NuspecProperties>
<NuspecProperties>$(NuspecProperties);branch=$(GitBranch)</NuspecProperties>
<NuspecProperties>$(NuspecProperties);commit=$(GitCommitSha)</NuspecProperties>
<NuspecProperties>$(NuspecProperties);Reqnroll_FullFramework_Tools_TFM=$(Reqnroll_FullFramework_Tools_TFM)</NuspecProperties>
<NuspecProperties>$(NuspecProperties);Reqnroll_Core_Tools_TFM=$(Reqnroll_Core_Tools_TFM)</NuspecProperties>
</PropertyGroup>
</Target>
<Target Name="CleanupNupkgs" BeforeTargets="Build" >
<ItemGroup>
<Nupkgs2Delete Include="$(PackageOutputAbsolutePath)\*.*nupkg"/>
</ItemGroup>
<Delete Files="@(Nupkgs2Delete)" />
</Target>
<Target Name="CopyNupkgToFolder" AfterTargets="Pack">
<ItemGroup>
<GeneratedNupkgs Include="$(PackageOutputAbsolutePath)\*.*nupkg"/>
</ItemGroup>
<Copy SourceFiles="@(GeneratedNupkgs)" DestinationFolder="$(MSBuildThisFileDirectory)GeneratedNuGetPackages\$(Configuration)" />
</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>