Skip to content

Instantly share code, notes, and snippets.

@johnkors
Created December 8, 2016 12:37
Show Gist options
  • Save johnkors/a27cab4f1236a29780892d4e764912eb to your computer and use it in GitHub Desktop.
Save johnkors/a27cab4f1236a29780892d4e764912eb to your computer and use it in GitHub Desktop.
Why use NETStandard.Library as a dependency instead of explicitly defining what you use from the BCL (NETStandard.Library)
https://aspnetcore.slack.com/archives/dotnet-core/p1481195518000050
johnkors [12:11 PM]
what do I, as a library author, gain by depending on `NETStandard.Library` instead of explicitly _just_ the nugets I need? (edited)
johnkors [12:26 PM]
- Some do : https://www.nuget.org/packages/xunit.abstractions/ @bradwilson
- Others don't : https://www.nuget.org/packages/Newtonsoft.Json/9.0.1 , @jamesnk
Wonder what's "better"; or why one would prefer one over the other. (edited)
thomascastiglione [12:48 PM]
you will soon be semi-required to depend on netstandard.library
[12:48]
it is becoming an automatic thing that isn't explicitly specified
[12:48]
microsoft's original plan was that people would use granular deps to reduce deployment sizes
[12:49]
but after initial release and feedback it turned out this was not very useful for many people and a big hassle
[12:49]
so the plan these days is to not bother
[12:49]
except when you REALLY need to
[12:49]
additional tools are being developed to reduce deployment sizes a different way
[12:49]
a 'linking' step which removes components of the library that weren't used
tore.lervik [12:56 PM]
So moving the action from user choice to build automation would be nice.
johnkors [1:18 PM]
> you will soon be semi-required to depend on netstandard.library
> it is becoming an automatic thing that isn't explicitly specified
How so, exactly..?
[1:19]
> but after initial release and feedback it turned out this was not very useful for many people and a big hassle
.. because..? the BCL won't change that much? or often?
thomascastiglione [1:23 PM]
how so: in new-csproj, when you use the netstandardxx tfm, it will automatically reference the NETStandard.Library package
[1:23]
unless explicitly removed or overridden
johnkors [1:24 PM]
ah, for _new_ projects. OK
thomascastiglione [1:24 PM]
yep
[1:24]
well
[1:24]
also for existing ones that get migrated!
johnkors [1:24 PM]
true :smile:
thomascastiglione [1:24 PM]
it's not a template thing
[1:24]
it's an actual feature of the sdk
[1:24]
if you DO want to omit it you still can with the normal msbuild syntax for removing an Item, `<PackageReference Remove="NETStandard.Library"/>`
[1:24]
but i don't think many people will do that
[1:24]
(or even be aware that it is an option)
[1:25]
you could override the version, similarly, with `<PackageReference Update="NETStandard.Library" Version="whatever.whatever"/>`, so full flexibility will remain
[1:26]
as for why it wasn't useful, i think it's because most people are running .net core programs on machines with a .net core runtime installed, rather than standalone..
[1:26]
and the runtime comes with all the packages in the stdlib
[1:26]
so there was nothing actually gained most of the time
[1:26]
just complexity added
johnkors [1:28 PM]
hmm.. So, as a consumer of a nuget, I usually don't care what parts of the BCL is used, because i've most likely installed the runtime where I run my apps...? That's what you're saying?
thomascastiglione [1:28 PM]
yep
[1:28]
the whole BCL is generally present on the machine
[1:29]
(and is not duplicated into the app or anything)
johnkors [1:29 PM]
:+1:
[1:29]
so it's only a "issue" if you're creating standalone apps & really care about deploy size..?
thomascastiglione [1:30 PM]
yeah, at which point you might need to use a more complex project file to remove the implicit reference
[1:30]
(or wait for the linker tool)
johnkors [1:31 PM]
ah, so it actually get's harder(-ish) to omit the `NETStandard.Library` at some point as well.
thomascastiglione [1:31 PM]
i've got to go for now, but here's a github issue where the implicit reference behaviour is being discussed https://github.com/dotnet/sdk/pull/450
GitHub
Implicitly add PackageReference for NETStandard.Library if targeting .NET Standard by dsplaisted · Pull Request #450 · dotnet/sdk · GitHub
This PR will implicitly add a PackageReference to NETStandard.Library if the project is targeting .NETStandard and there isn't already a PackageReference to NETStandard.Library. This makes project...
[1:31]
not quite a final design as you can see from the discussion there
johnkors [1:33 PM]
Thx a lot for your time! :slightly_smiling_face:
[1:33]
subscribing to that issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment