.NET Standard Flashcards
What is the difference between portable class libraries and .net standard?
PCL requires recompilation for each intersection profile (target) you want to be compatible with. .net standard you compile once.
How does .net standard ensures backwards compatibility?
Because it only ADDS new apis every version, therefore the previous existing implemented api still work
What is the golden rule to define a .net std class lib?
target the lower version as possible since it’ll reach more platforms.
What does versioning in .net std look like?
1 - the higher the std version the more api but less plat.
2 - the lower the std ver the less apis but more plat.
how to create a .net std class lib that follows the golden rule?
create the lib using the latest version, then downgrade it until it doesn’t compile. choose the lowest
How to find what each version of .net standard implements?
on docs.microsoft.com or github. github has a diff between versions.
how to see the intermediate language code generated by a std class lib?
by using ILDasm
What is type forwarding in the .net standard ecosystem?
Is a technique used to allow the .net std class lib to instead of using its own contract to use the target contract (the one that the concrete application is using)
What is a concrete application?
is a application that targets anything but .net standard (runnable).
Details here: https://pasteboard.co/Jyc1W2q.png
What happens when you open .netstandard.dll in the concrete app folder in IL DASM?
It shows all the type forwardings to the concrete platform and no implementations.
What is Compatibility Shim (aka Compat Shim)? How it improves the interop of different targets on .net?
Compatibility Shim brings the .net standard interoperability with .net framework class libs, meaning .net std 2.0 can depend on a .net framework lib (4.6.1). Details at: https://pasteboard.co/JydsVmD.png
What happens when the referenced .net framework library uses non-supported-.net std apis?
a file not found exception will be thrown at runtime
What is .net portability analyzer extension? where to find it?
checks if the .net ptroject is portable to a target platform. find it in the online extensions of visual studio.
What are the 4 steps to convert a simple .net framework project to standard?
unload the project, edit the csproj and copy a .net std content project sdk, prop group and target framework, then remove the assembly info and property folders, then add back the dependencies as nuget packages.
Why do we need to install the newtonsoft.json lib twice (one in the .net std and other in the framework)?
Because the first work with package reference and the latter work with packages.config, therefore the file won’t be found in the assembly output directory.
How to make a .net framework project use nuget packages referenced in the dependencies’ csproj (.net core style) instead of packages.config file (framework style)?
Unload the project, and add a new entry in the property group element: PackageReference
How to target multiple platforms in a .net std library?
edit the csproj from targetframework to frameworks, then define the frameworks with the proper mnemonic net461;netstandard1.3
How to open a source code using a specific target framework?
there is a dropdown in the top of the source code screen where you can choose.
How to add dependencies for a specific target in the csproj file?
add a new item group with a condition to ‘$(TargetFramework) == ‘net461’ then add the reference elements beneath it
What to do in old version of visual studio 15 with multi target-reference dependencies? supposed to work on 16… does it apply to nuget references as well?
you need to multi target the whole “cascade of dependencies) otherwise it’ll always fallback to the first dependency (which is likely to be std)
nuget package works just fine.
What is the microsofr.windows.compatibility nuget package?
has several apis, also for platform specific but be aware of PlatformNotFound exceptions in linux environments.
can i add local sources for nuget packages?
yes.. just click the gear icon and add the new source… then select the source in the nuget screen
do all the targets of my nuget package appear in the selected nupkg?
YES… check the dependencies section (.netframework section and .netstd section)