You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
extern alias support for NuGet package references #4989
Reacted by Julien Lebosquain, Arthur Khashaev, Robert Husák, Tomáš Matoušek, Nate McMaster, Ivan Pashchenko, Alexander Prokhorov, Eli Arbel, Paul Lemke, Friedrich von Never and 62 more
Reacted by Bruno Garcia, Jonathan Kellenberg, Tran Nguyen, Paul Lemke, Gian Maria, thomhubers, Alex Zaytsev, Alexander Kholodov, Luc Gauthier, Michael List and 9 more
IIRC you can configure NuGet to store the NuGet packages in an packages folder instead of using the cache in the users home folder using the NuGet.config. This allows you to manually specify project-relative assembly references (via Reference Update) which can include the alias. The problem with this approach is, that you have to update the reference whenever the package version changes. However, you can restore the packages into folders without the package version of you don't have conflicting package versions.
It would be great if someone on the NuGet team could point in the right direction of the repo that requires the change. I am sure people are happy to look if they know where to look.
I'll help sponsor, point to the locations that need to change in SDK, ProjectSystem (NuGet team will need to jump in on the nuget side, as I don't have context), and driving this through, if a community member wants to pick up the design/changes.
Reacted by Andrew McClenaghan, Erico Freitas, Stefan Buehler, Mike Schuld, Robert Husák, Lukas Lansky, Colt, Alexander Prokhorov, Ivan, ONUKI Masanori and 45 more
Reacted by Mesut Pişkin, Are Almaas, Dmitry, Oleksii Romanchenko and michaelgayeski
Reacted by Nicholaos Bilalis, Christian, Mohammad Rebati, Michael List, Vi, Justin Adler, AIDA and Are Almaas
Reacted by michaelgayeski
Reacted by Mesut Pişkin, Iskander Sierra, Are Almaas, Shubham Rane, salamoun and Fabiosnts
Hi!
We're waiting for Visual Studio 16.7 to use this feature, do you know if it's available yet in any of the VS16.7 previews? Saw that Preview 3 was just released.
Got it to work with VS16.7 Preview 3.1 and .NET 5 Preview 6 with a .NET project SDK style.
Trying to get it to work with .NET Framework 4.8 with old csproj style,, any tips on how to get it working there? @nkolev92
It works when the csproj is SDK-style, but our solution projects uses the old style.
Edit: After some investigating, it seems that the dll for Microsoft.NuGet.Build.Tasks that is shipped with Visual Studio 16.7 Preview 3.1 does not contain your changes from dotnet/NuGet.BuildTasks#70 so I guess that's the issue.
No, this cannot be used to alias different versions of the same package that has the same identifier. This is entirely used to alias assemblies within a package.
@tdhatcher I'm aware of no plans to allow the ability to reference multiple versions of the same NuGet packages, but one of the NuGet folks would need to chime in, @nkolev92 .
@nkolev92 my feedback is as someone who is not familar with inner workings of nuget package resolution. I'm curious if this doesn't exist because it's more of a technical hurdle to accomplish or more of a logical decision?
It seems if two or more distinctly named packages can resolve namespace collision with aliases then two or more of the same named packages should be able to resolve namespace collision.
I haven't really come across a solid prescribed strategy as for how to actually implement your API versions especially when breaking changes are present (and without separately hosting older version of the API). Just that there is flexibility in ASP.NET Core to support mapping multiple API versions to different controllers to handle the request/response (concurrently in the same running instance of an API).
Consider a common scenario when you publish a nuget package that serves as a convenient SDK for your API. That SDK contains all the classes that act as the contracts and client for consumers to interact with the API. The version of the SDK's nuget package is kept in-sync with the version of the API (eg. you'd use version 5 of the SDK you are communicating with v5 of the API).
By allowing aliases on same Nuget package with different versions, the API implementation would be able to reference the proper version of the SDK nuget package to obtain the proper contracts for the specific version of API controllers.
This approach would be in contrast to an approach of maintaining a versioned yet disjointed SDK library separately while in the API it is cloning/maintaining multiple versions of the contracts globbed together in a single project to support backwards compatibility. Seems like a clean option like this is missing.
@tdhatcher Having multiple versions of the same assembly (by extension of package) is a pretty involved feature.
I won't be able to address all your concerns, but one difficult challenge is what happens transitively. Sure if you reference a package directly, you can choose to alias it's assemblies, but what happens for the transitive dependencies that might have some incompatibilities?
You're likely to need some sort of assembly rewriting to make this work, which would have it's own set of problems.
If you'd like you can file a different issue with that ask.
The first thing that would need to happen to make progress on your idea is for the tooling overall to support multiple versions of the same package within 1 project.
@tdhatcher I appreciate the callout 😉 , but an API version is not like a Semantic Version or assembly version; this is a false equivalency. Backward compatibility should in no way be implied or inferred from any API version. This is a common misconception. The rules for versioning binaries are quite different and are well-known across many languages and tools. These rules do not generically apply to an API. Even if the changes to the message body of an API is additive, a server cannot guarantee that the client implements a tolerant reader and will not break. There's nothing about 1.1 that says it's backward compatible with 1.0. I could have just as easily removed a data attribute and that would be considered a minor change. The conflation with numbers for API versions and binary versions are one reason why dates are often a better choice for an API version. Nothing about 2023-01-01 implies that it is compatible with 2019-07-01. 😸
API authors that vend a client that they want to have affinity to the API version usually take one of the following approaches:
Include all supported API versions in a single package, separated by namespace
Include a single package that maps to the most recent supported API versions
Include a meta package that maps to individual packages corresponding to independently versions clients
While it is possible, it's usual and uncommon to need multiple versions of the same API simultaneously. Azure SDKs are backed by versioned Azure APIs. When you use a particular version of the client SDK, you typically don't think about the backing API version and certainly not multiple API versions at the same time. As @nkolev92 mentioned, the complexity of SxS assemblies is involved and goes beyond just aliasing. Even if you got it to work, it's pretty painful for package consumers. I doubt many would actually want that.
There are like other ways to achieve your goals, including, but not limited to having a clearly defined API versioning policy such as N-2.
Activity
davkean commentedon Apr 6, 2017
Great suggestion. I'll move this over to the NuGet repo, they own the syntax for PackageReference.
andymac4182 commentedon May 3, 2017
This would be great since we are running into this issue due to https://www.nuget.org/packages/StackExchange.Redis/ and https://www.nuget.org/packages/StackExchange.Redis.StrongName/
brianpos commentedon May 3, 2017
We have this issue to if we want to add both of these
https://www.nuget.org/packages/Hl7.Fhir.DSTU2
https://www.nuget.org/packages/Hl7.Fhir.STU3
wburgers commentedon May 23, 2017
@brianpos exactly the same problem here.
We would like to run both fhir versions next to each other.
brianpos commentedon May 23, 2017
@wburgers i have a project using the extern alias trick https://github.com/brianpos/FhirPathTester but do have to set manually after inclusion. So can't wait for this to be fixed.
JoseFMP commentedon Jun 21, 2017
+1, can't wait for this. I think this is important because right now different packages implementing same namespaces.
@brianpos could you share your trick please?
fubar-coder commentedon Jun 21, 2017
IIRC you can configure NuGet to store the NuGet packages in an packages folder instead of using the cache in the users home folder using the NuGet.config. This allows you to manually specify project-relative assembly references (via
Reference Update) which can include the alias. The problem with this approach is, that you have to update the reference whenever the package version changes. However, you can restore the packages into folders without the package version of you don't have conflicting package versions.JoseFMP commentedon Jun 21, 2017
Ok, so basically referencing the .dll quasi-manually and including then the alias, right? I was also thinking about that as a work around
davkean commentedon Jun 21, 2017
As a side note, a workaround is to write a target that does something like this: https://github.com/dotnet/project-system/blob/master/build/Targets/VSL.Imports.targets#L340.
Here we're setting the EmbedInteropTypes metadata, but the same could be applied to alias.
andymac4182 commentedon Jun 21, 2017
It would be great if someone on the NuGet team could point in the right direction of the repo that requires the change. I am sure people are happy to look if they know where to look.
davkean commentedon Jun 21, 2017
I think they'll need a design first, I don't see a flushed out proposal on syntax/behavior. Once we do that, we'll then need to work with the project systems (http://github.com/dotnet/project-system) and SDK (http://github.com/dotnet/project-system) to add/respect the property so that it can be passed to NuGet/show in Properties, etc, added to the
<REference/>when we dynamically produce them, and then plumbed through pack (what does an aliased set of references do when we add the package as a reference in the nuspec?). Just to set expectations, this isn't a couple of lines change.davkean commentedon Jun 21, 2017
I'll help sponsor, point to the locations that need to change in SDK, ProjectSystem (NuGet team will need to jump in on the nuget side, as I don't have context), and driving this through, if a community member wants to pick up the design/changes.
gertjvr commentedon Jun 23, 2017
After some experimentation and got it to work.
Placed the below snippet into my csproj file where I had both references of
StackExchange.RedisandStackExchange.Redis.StrongNamenuget dependencies.JoseFMP commentedon Jun 23, 2017
@gertjvr sounds great! I will give it a try over here
ewoutkramer commentedon Jun 26, 2017
What would that entail? Sorry, I am not very familiar with the process!
70 remaining items
TFTomSun commentedon Jun 12, 2020
@nkolev92 are the aliases transistive? I mean, are they applied to indirect, transistive dependencies, too?
nkolev92 commentedon Jun 12, 2020
They only apply to the package reference they are specified on.
The challenge with applying to transitive dependencies is the
diamond dependencyscenario where: Project -> A -> C and Project -> B -> C.For the time being the answer to how do I apply metadata to a transitive package still remains
elevate it to top level.YanerTavuz commentedon Jun 26, 2020
Hi!
We're waiting for Visual Studio 16.7 to use this feature, do you know if it's available yet in any of the VS16.7 previews? Saw that Preview 3 was just released.
nkolev92 commentedon Jun 26, 2020
@YanerTavuz Preview 3 should have it
YanerTavuz commentedon Jun 28, 2020
Got it to work with VS16.7 Preview 3.1 and .NET 5 Preview 6 with a .NET project SDK style.
Trying to get it to work with .NET Framework 4.8 with old csproj style,, any tips on how to get it working there? @nkolev92
It works when the csproj is SDK-style, but our solution projects uses the old style.
Edit: After some investigating, it seems that the dll for Microsoft.NuGet.Build.Tasks that is shipped with Visual Studio 16.7 Preview 3.1 does not contain your changes from dotnet/NuGet.BuildTasks#70 so I guess that's the issue.
brian-pickens commentedon Sep 4, 2020
Will this work to alias different versions of the same package?
fubar-coder commentedon Oct 19, 2020
Yes
davkean commentedon Oct 19, 2020
No, this cannot be used to alias different versions of the same package that has the same identifier. This is entirely used to alias assemblies within a package.
tdhatcher commentedon Jan 31, 2023
@davkean Is there any plan to enable this in the case of "different version of same nuget package"?
This would be very handy for versioning classes and allowing a single service to interop with both (or many versions) concurrently using aliases.
davkean commentedon Jan 31, 2023
@tdhatcher I'm aware of no plans to allow the ability to reference multiple versions of the same NuGet packages, but one of the NuGet folks would need to chime in, @nkolev92 .
nkolev92 commentedon Jan 31, 2023
There are no active plans to enable multiple versions of the same package in a project at this point.
tdhatcher commentedon Jan 31, 2023
@nkolev92 my feedback is as someone who is not familar with inner workings of nuget package resolution. I'm curious if this doesn't exist because it's more of a technical hurdle to accomplish or more of a logical decision?
It seems if two or more distinctly named packages can resolve namespace collision with aliases then two or more of the same named packages should be able to resolve namespace collision.
I haven't really come across a solid prescribed strategy as for how to actually implement your API versions especially when breaking changes are present (and without separately hosting older version of the API). Just that there is flexibility in ASP.NET Core to support mapping multiple API versions to different controllers to handle the request/response (concurrently in the same running instance of an API).
Consider a common scenario when you publish a nuget package that serves as a convenient SDK for your API. That SDK contains all the classes that act as the contracts and client for consumers to interact with the API. The version of the SDK's nuget package is kept in-sync with the version of the API (eg. you'd use version 5 of the SDK you are communicating with v5 of the API).
By allowing aliases on same Nuget package with different versions, the API implementation would be able to reference the proper version of the SDK nuget package to obtain the proper contracts for the specific version of API controllers.
This approach would be in contrast to an approach of maintaining a versioned yet disjointed SDK library separately while in the API it is cloning/maintaining multiple versions of the contracts globbed together in a single project to support backwards compatibility. Seems like a clean option like this is missing.
Allowing aliases for the same package but different versions would be a very complementary feature to ASP.NET Core API versioning. https://github.com/dotnet/aspnet-api-versioning/wiki/Existing-Services-Quick-Start
nkolev92 commentedon Jan 31, 2023
@tdhatcher Having multiple versions of the same assembly (by extension of package) is a pretty involved feature.
I won't be able to address all your concerns, but one difficult challenge is what happens transitively. Sure if you reference a package directly, you can choose to alias it's assemblies, but what happens for the transitive dependencies that might have some incompatibilities?
You're likely to need some sort of assembly rewriting to make this work, which would have it's own set of problems.
If you'd like you can file a different issue with that ask.
The first thing that would need to happen to make progress on your idea is for the tooling overall to support
multiple versions of the same package within 1 project.commonsensesoftware commentedon Jan 31, 2023
@tdhatcher I appreciate the callout 😉 , but an API version is not like a Semantic Version or assembly version; this is a false equivalency. Backward compatibility should in no way be implied or inferred from any API version. This is a common misconception. The rules for versioning binaries are quite different and are well-known across many languages and tools. These rules do not generically apply to an API. Even if the changes to the message body of an API is additive, a server cannot guarantee that the client implements a tolerant reader and will not break. There's nothing about
1.1that says it's backward compatible with1.0. I could have just as easily removed a data attribute and that would be considered a minor change. The conflation with numbers for API versions and binary versions are one reason why dates are often a better choice for an API version. Nothing about2023-01-01implies that it is compatible with2019-07-01. 😸API authors that vend a client that they want to have affinity to the API version usually take one of the following approaches:
While it is possible, it's usual and uncommon to need multiple versions of the same API simultaneously. Azure SDKs are backed by versioned Azure APIs. When you use a particular version of the client SDK, you typically don't think about the backing API version and certainly not multiple API versions at the same time. As @nkolev92 mentioned, the complexity of SxS assemblies is involved and goes beyond just aliasing. Even if you got it to work, it's pretty painful for package consumers. I doubt many would actually want that.
There are like other ways to achieve your goals, including, but not limited to having a clearly defined API versioning policy such as
N-2.