-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathDirectory.Build.targets
More file actions
29 lines (24 loc) · 1.87 KB
/
Directory.Build.targets
File metadata and controls
29 lines (24 loc) · 1.87 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
<Project>
<!-- Clear NuGet packages after successful build for projects that generate packages -->
<Target Name="ClearLocalNuGetPackages" AfterTargets="Build" Condition="'$(GeneratePackageOnBuild)' == 'true'">
<PropertyGroup>
<NuGetPackagesPath>$(USERPROFILE)\.nuget\packages</NuGetPackagesPath>
<!-- Use PackageId if specified, otherwise use AssemblyName, otherwise use MSBuildProjectName -->
<CurrentPackageId Condition="'$(PackageId)' != ''">$(PackageId)</CurrentPackageId>
<CurrentPackageId Condition="'$(CurrentPackageId)' == '' AND '$(AssemblyName)' != ''">$(AssemblyName)</CurrentPackageId>
<CurrentPackageId Condition="'$(CurrentPackageId)' == ''">$(MSBuildProjectName)</CurrentPackageId>
<!-- Convert to lowercase for NuGet folder name -->
<CurrentPackageIdLower>$(CurrentPackageId.ToLowerInvariant())</CurrentPackageIdLower>
</PropertyGroup>
<Message Text="Clearing local NuGet package cache for $(CurrentPackageId)..." Importance="high" />
<!-- Windows -->
<Exec Condition="'$(OS)' == 'Windows_NT'"
Command="if exist "$(NuGetPackagesPath)\$(CurrentPackageIdLower)" ( echo Deleting $(NuGetPackagesPath)\$(CurrentPackageIdLower) && rd /s /q "$(NuGetPackagesPath)\$(CurrentPackageIdLower)" )"
ContinueOnError="true" />
<!-- Linux/Mac -->
<Exec Condition="'$(OS)' != 'Windows_NT'"
Command="if [ -d "$(NuGetPackagesPath)/$(CurrentPackageIdLower)" ]; then echo "Deleting $(NuGetPackagesPath)/$(CurrentPackageIdLower)"; rm -rf "$(NuGetPackagesPath)/$(CurrentPackageIdLower)"; fi"
ContinueOnError="true" />
<Message Text="Finished clearing local NuGet package cache for $(CurrentPackageId)." Importance="high" />
</Target>
</Project>