File tree Expand file tree Collapse file tree 1 file changed +27
-4
lines changed
Expand file tree Collapse file tree 1 file changed +27
-4
lines changed Original file line number Diff line number Diff line change 11<Project >
2- <Target Name =" PreBuild" BeforeTargets =" PreBuildEvent" >
3- <Exec Condition =" '$(IsWindows)'=='true' And $(PackageId) != ''" Command =" RD /S /Q " %25USERPROFILE%25\.nuget\packages\$(PackageId)" " />
4- <Exec Condition =" '$(IsLinux)'=='true' And $(PackageId) != ''" Command =" rm -rf " %25USERPROFILE%25\.nuget\packages\$(PackageId)" " />
5- </Target >
2+ <!-- Clear NuGet packages after successful build for projects that generate packages -->
3+ <Target Name =" ClearLocalNuGetPackages" AfterTargets =" Build" Condition =" '$(GeneratePackageOnBuild)' == 'true'" >
4+ <PropertyGroup >
5+ <NuGetPackagesPath >$(USERPROFILE)\.nuget\packages</NuGetPackagesPath >
6+ <!-- Use PackageId if specified, otherwise use AssemblyName, otherwise use MSBuildProjectName -->
7+ <CurrentPackageId Condition =" '$(PackageId)' != ''" >$(PackageId)</CurrentPackageId >
8+ <CurrentPackageId Condition =" '$(CurrentPackageId)' == '' AND '$(AssemblyName)' != ''" >$(AssemblyName)</CurrentPackageId >
9+ <CurrentPackageId Condition =" '$(CurrentPackageId)' == ''" >$(MSBuildProjectName)</CurrentPackageId >
10+ <!-- Convert to lowercase for NuGet folder name -->
11+ <CurrentPackageIdLower >$(CurrentPackageId.ToLowerInvariant())</CurrentPackageIdLower >
12+ </PropertyGroup >
13+
14+ <Message Text =" Clearing local NuGet package cache for $(CurrentPackageId)..." Importance =" high" />
15+
16+ <!-- Windows -->
17+ <Exec Condition =" '$(OS)' == 'Windows_NT'"
18+ Command =" if exist " $(NuGetPackagesPath)\$(CurrentPackageIdLower)" ( echo Deleting $(NuGetPackagesPath)\$(CurrentPackageIdLower) && rd /s /q " $(NuGetPackagesPath)\$(CurrentPackageIdLower)" )"
19+ ContinueOnError =" true" />
20+
21+ <!-- Linux/Mac -->
22+ <Exec Condition =" '$(OS)' != 'Windows_NT'"
23+ Command =" if [ -d " $(NuGetPackagesPath)/$(CurrentPackageIdLower)" ]; then echo " Deleting $(NuGetPackagesPath)/$(CurrentPackageIdLower)" ; rm -rf " $(NuGetPackagesPath)/$(CurrentPackageIdLower)" ; fi"
24+ ContinueOnError =" true" />
25+
26+ <Message Text =" Finished clearing local NuGet package cache for $(CurrentPackageId)." Importance =" high" />
27+ </Target >
28+
629</Project >
You can’t perform that action at this time.
0 commit comments