Skip to content
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

Can we do Maven style snapshots? #7092

Closed
red8888 opened this issue Jul 6, 2018 · 13 comments
Closed

Can we do Maven style snapshots? #7092

red8888 opened this issue Jul 6, 2018 · 13 comments
Labels
WaitingForCustomer Applied when a NuGet triage person needs more info from the OP

Comments

@red8888
Copy link

red8888 commented Jul 6, 2018

Now that project.json is dead how can you emulate maven style snapshots?

I want to mark a package as a snapshot version so nuget/Visual Studio always downloads the most current version of that package.

@nkolev92
Copy link
Member

nkolev92 commented Jul 6, 2018

NuGet already supports pre-release packages, which is kind of what snapshots are trying to achieve.

NuGet also has the concept of floating versions that allows you get the latest prerelease version of that said package.

What exactly are you trying to achieve here?
Please also refer to https://semver.org/#spec-item-9. Relying on a mix of stable/prerelease packages is generally not the best idea.

@nkolev92 nkolev92 added the WaitingForCustomer Applied when a NuGet triage person needs more info from the OP label Jul 6, 2018
@red8888
Copy link
Author

red8888 commented Jul 7, 2018

I want to mark a package as a snapshot version so nuget/Visual Studio always downloads the most current version of that package.

Like maven does it- this isn't a wierd use case.

Can the prerelease thing do that? I want to not have to modify the version number and have nuget always redownload the latest version- like maven snapshots

@nkolev92
Copy link
Member

nkolev92 commented Jul 7, 2018

Even with maven, you still can't re-download the same version.
You need to purge the local repository of that version.

You can achieve a similar thing. The thing is that each package you release should have a unique identifier.
Then you can just float the prerelease version.
Example 1.0.0-rc.* would always get the latest RC (there's 30 min http caching as a perf optimization, but that can be bypassed).
Look at for example https://dotnet.myget.org/feed/nuget-build/package/nuget/NuGet.Frameworks, how we publish a package with each build.

Please refer to https://docs.microsoft.com/en-us/nuget/consume-packages/dependency-resolution and https://docs.microsoft.com/en-us/nuget/reference/package-versioning#version-ranges-and-wildcards for more info.

@red8888
Copy link
Author

red8888 commented Jul 7, 2018

"--update-snapshots" correct me if im wrong but maven absolutely can and thats kind of the whole point!

Doing it your way means I still need to update the package reference right? Go into nuget package manager and install that version right? Maybe im missing something?

Maybe there is a VS extension or a build task that can selectively run "Update-Package –reinstall" on certain packages- by doing a string match for some identifying token in the version number or something?

@nkolev92
Copy link
Member

nkolev92 commented Jul 7, 2018

@red8888
No you don't need to change the csproj.
You only need to change it when you start depending on an entirely different version.
You would just have 1.0.0-rc.* and then whenever you run some specific restores it will download the latest version .
Those specific restores are listed here.
Please note that with the future addition of repeatable builds those gestures may change.

@red8888
Copy link
Author

red8888 commented Jul 9, 2018

Thanks for answering my questions. So to set that version like "1.0.0-rc.*" do I do that in packages.config or in PackageReference in csproj files? Our users are most familiar with nuget package manager though, is there a way to set a wildcard version from that GUI too?

Thanks again!

@nkolev92
Copy link
Member

nkolev92 commented Jul 9, 2018

@red8888

Floating versions are only supported with PackageReferences in csproj.

packages.config is a rather old design at this point and we prefer if customers move towards PR whenever appropriate.

Floating versions docs

There's currently no UI handling for floating versions unfortunately.
#3788
#3101

Please note that updates/installs are way more performant and consistent in PackageReference that they don't need to be changed with the UI.

@PatoBeltran
Copy link

Closing as all the questions seem to be resolved, feel free to reopen or create a new issue if there are further related concerns.

@drdamour
Copy link

one of the nice things about snapshots is that if i maven publish a project with snapshot it gets pushed to my local maven repo, and then when i refresh dependencies over in another project it'll see that local snapshot and pull it in fairly quickly. This makes REPL on a dependency very easy...i'm wondering what the equivalent flow is for NuGet

@benlongo
Copy link

Having snapshot style managing would be very nice for local development of packages and the consumer of the package.

@nickhoeferpickpro
Copy link

nickhoeferpickpro commented Nov 27, 2022

Having snapshot style managing would be very nice for local development of packages and the consumer of the package.

Agreed! I have been spending the last couple days trying to figure this out. I did something like this to achieve a similar effect.
I borrowed the idea from @thesushil here #9891

	
<Target Name="DeleteLocalCache" BeforeTargets="Pack">
  <RemoveDir Directories="$(NugetPackageRoot)$(PackageId.ToLower())\$(version)" />
  <Message Text="Cleaning $(NugetPackageRoot)$(PackageId.ToLower())\$(version)" />
</Target>

<Target Name="UpdateLocalCache" AfterTargets="Pack">		
  <Message Text="creating diretory $(NugetPackageRoot)$(PackageId.ToLower())\$(version)" Importance="high" />
  <MakeDir Directories="$(NugetPackageRoot)$(PackageId.ToLower())\$(version)" />
  <Message Text="copying file $(PackageOutputPath)$(AssemblyName).$(version).nupkg" Importance="high" />
  <Copy SourceFiles="$(PackageOutputPath)$(AssemblyName).$(version).nupkg" DestinationFolder="$(NugetPackageRoot)$(PackageId.ToLower())\$(version)" />
		
  <Exec Command="tar -xf $(NugetPackageRoot)$(PackageId.ToLower())\$(version)\$(AssemblyName).$(version).nupkg -C $(NugetPackageRoot)$(PackageId.ToLower())\$(version)" />
  <Exec Command="certutil -hashfile $(NugetPackageRoot)$(PackageId.ToLower())\$(version)\$(AssemblyName).$(version).nupkg SHA512 &gt; $(NugetPackageRoot)$(PackageId.ToLower())\$(version)\temp1.txt" />
  <Exec Command="more +1 $(NugetPackageRoot)$(PackageId.ToLower())\$(version)\temp1.txt &gt; $(NugetPackageRoot)$(PackageId.ToLower())\$(version)\temp2.txt " />
  <Exec Command="powershell Get-Content $(NugetPackageRoot)$(PackageId.ToLower())\$(version)\temp2.txt -First 1 &gt; $(NugetPackageRoot)$(PackageId.ToLower())\$(version)\$(AssemblyName).$(version).nupkg.sha512" />
  <Exec Command="del /f $(NugetPackageRoot)$(PackageId.ToLower())\$(version)\temp1.txt" />
  <Exec Command="del /f $(NugetPackageRoot)$(PackageId.ToLower())\$(version)\temp2.txt" />
</Target>

If anyone knows a more elegant way to handle this, I'm all ears. Changing version numbers each time just for local development is just silly. semver is great and everything but we shouldn't be forced to adhere to it just for the sake of purity because doing so results in dirty hacks or workarounds.

@nickhoeferpickpro
Copy link

I think #6579 is related.

@derekm
Copy link

derekm commented Aug 21, 2024

@red8888 -- I don't think these people have ever developed with Java or Maven, so they don't know what they're missing with how clunky nugets & multi-project solutions & cross-solution development are in C#/.NET!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WaitingForCustomer Applied when a NuGet triage person needs more info from the OP
Projects
None yet
Development

No branches or pull requests

7 participants