-
-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add automatic cleanups to improve the inner devloop #17
Conversation
When working with packages built locally, it's quite common to dogfood those packages from sample projects locally. This can use a fixed package version for the locally produced packages, or auto-incremented versions. Also, the referencing projects might choose to use wildcards when testing local packages too. The caching mechanisms built into NuGet make this process a bit more cumbersome than necessary: if you build a fixed version package, you will never get a newly built version restored in a project elsewhere in the machine because NuGet will believe the one in the cache is already the latest. The HTTP-level cache implemented on top of the package cache also works against you in that case even if you clean that folder. And wildcards don't make things much better unless you clean those caches too. In addition, if you increment package versions when building locally too, the package output path will continuously be filled up with older versions unnecessarily. This commit adds support for automatically fixing all those issues while still causing minimal disruption or performance problems for other packages and projets in your machine, as follows: * The entire cleanup only is in place for packable projects, and in local (non-CI) builds * It can be turned off entirely by setting `EnablePackCleanup=false`. * It cleans the specific package folder in the cache for the current PackageId: nuget creates a subfolder in the package cache dir for each package id, and places all versions inside. By removing just that folder, you effectively clean the cache for that package and no others. * It cleans the HTTP cache too: this cannot be done selectively for a specific package id, and therefore can be turned off by setting `CleanHttpNuGetCacheOnPack=false` if it causes performance issues. In my experience, it doesn't since the HTTP cache is just an optimization for offline scenarios (I think?). I have used this approach for years on multiple projects with multiple packaging approaches and at this point I think it deserves being built-in in nugetizer.
@kzu , sorry for necro-posting, but I have a direct question related to inner devloop. Maybe I missed something and it's documented somewhere, or maybe it's just to obvious, therefore not documented? :) Some real case scenario:
|
Not sure I understand the scenario. Perhaps you can create a new issue and explain what works and doesn't in the current flow? (and what's your ideal behavior). You can turn off all the cleanup by just setting |
I think I managed to workaround it, but had to deviate a bit from what was suggested in documentation.
Instead of this: <RestoreSources>https://api.nuget.org/v3/index.json;$(RestoreSources)</RestoreSources>
<RestoreSources Condition="Exists('$(MSBuildThisFileDirectory)..\..\bin\')">
$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)..\..\bin'));$(RestoreSources)
</RestoreSources> I ended with this (removed <RestoreSources>https://api.nuget.org/v3/index.json;$(RestoreSources)</RestoreSources>
<RestoreSources Condition="Exists('$(MSBuildThisFileDirectory)..\..\bin\')">
$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)..\..\bin'));
</RestoreSources> Not sure why it works like that, but if I leave it like in documentation - from time to time it was restoring packages from the remote repository anyway.
So, overall it still not a flawless development experience - some manual steps are involved, also messing up with NuGet caches often makes Rider/VisualStudio to act up and scream about broken references temporarily (some additional pressure on CPU/Memory, etc). However it's still way better than everytime publishing packages to remote repository when you want just to test something. I can live with it. :) |
<Project>
<PropertyGroup>
<ThisAssemblyDir>C:\Code\ThisAssembly\bin</ThisAssemblyDir>
<RestoreSources Condition="Exists('$(ThisAssemblyDir)')">$(ThisAssemblyDir);$(RestoreSources)</RestoreSources>
<NuGetizerDir>C:\Code\nugetizer\bin</NuGetizerDir>
<NuGetizerDev Condition="Exists('$(NuGetizerDir)\NuGetizer.42.42.42.nupkg')">true</NuGetizerDev>
<RestoreSources Condition="'$(NuGetizerDev)' == 'true'">$(NuGetizerDir);$(RestoreSources)</RestoreSources>
<GitInfoDir>C:\Code\GitInfo\bin</GitInfoDir>
<GitInfoDev Condition="Exists('$(GitInfoDir)\GitInfo.42.42.42.nupkg')">true</GitInfoDev>
<RestoreSources Condition="'$(GitInfoDev)' == 'true'">$(GitInfoDir);$(RestoreSources)</RestoreSources>
</PropertyGroup>
<ItemGroup Condition="Exists('$(ThisAssemblyDir)')">
<PackageReference Update="ThisAssembly.AssemblyInfo" Version="42.42.42" />
<PackageReference Update="ThisAssembly.Constants" Version="42.42.42" />
<PackageReference Update="ThisAssembly.Metadata" Version="42.42.42" />
</ItemGroup>
<ItemGroup>
<PackageReference Condition="'$(NuGetizerDev)' == 'true'" Update="NuGetizer" Version="42.42.42" />
<PackageReference Condition="'$(GitInfoDev)' == 'true'" Update="GitInfo" Version="42.42.42" />
</ItemGroup>
</Project>
|
Thanks for more input, I will try with updating references via targets. |
When working with packages built locally, it's quite common to dogfood those packages from sample projects locally. This can use a fixed package version for the locally produced packages, or auto-incremented versions. Also, the referencing projects might choose to use wildcards when testing local packages too.
The caching mechanisms built into NuGet make this process a bit more cumbersome than necessary: if you build a fixed version package, you will never get a newly built version restored in a project elsewhere in the machine because NuGet will believe the one in the cache is already the latest. The HTTP-level cache implemented on top of the package cache also works against you in that case even if you clean that folder. And wildcards don't make things much better unless you clean those caches too.
In addition, if you increment package versions when building locally too, the package output path will continuously be filled up with older versions unnecessarily.
This commit adds support for automatically fixing all those issues while still causing minimal disruption or performance problems for other packages and projets in your machine, as follows:
EnablePackCleanup=false
.CleanHttpNuGetCacheOnPack=false
if it causes performance issues. In my experience, it doesn't since the HTTP cache is just an optimization for offline scenarios (I think?).I have used this approach for years on multiple projects with multiple packaging approaches and at this point I think it deserves being built-in in nugetizer.