0

Suppose that at the top of my *.cs file, I am including some dependencies:

using System;
using System.Collections.Generic;
using System.IdentityModel.Tokens.Jwt;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;

Is it possible to also display version numbers here as shown below?

using System; //1.0.1
using System.Collections.Generic; //22.0.1
using System.IdentityModel.Tokens.Jwt; //3.56.2
etc
Aryan Firouzian
  • 1,940
  • 5
  • 27
  • 41
Alex Gordon
  • 57,446
  • 287
  • 670
  • 1,062

1 Answers1

2

No, you can't. This is because C# and .NET is not like Java, TypeScript and other languages where the concept of namespaces, packages and libraries are combined - in .NET they're entirely separate: multiple packages can include the same library DLL file, and multiple library DLLs can contribute towards shared and different namespaces.

For example, the System namespace has its members in mscorlib.dll, System.dll, System.Core.dll, and others. None of these assemblies belong to any particular package as they're part of the BCL in your CLR implementation. Furthermore, anyone is free to declare their own types in namespace System.

With respect to "packages": the CLR is completely unaware of them: they're a design-time concern; instead all it cares about is what DLL files to link. You don't have to use NuGet packages at all (.NET developers survived just fine for the first 13 years without a built-in package manager).

Note that NuGet allows you to have multiple DLL files a single package, and the package author does not need to "own" (legally or otherwise) the DLLs contained within either, which means multiple NuGet packages can share the same assembly DLL, and those DLLs could share namespaces.

I take issue with these words of yours:

I am including some dependencies:

Remember, C# is not TypeScript - despite syntactic similarities (like C compared to C++) they're very different - it isn't appropriate to refer to namespace imports as "including dependencies" - it's just syntax - whereas in TypeScript the statement import { Foo } from './bar' is more than just syntax as it will invoke the runtime platform's package/module import system, whereas using in C# is an entirely inert statement that simply saves you from typing global::The.Full.Namespace.Name every time you use an identifier.

Dai
  • 141,631
  • 28
  • 261
  • 374
  • fine, but can't plugins like resharper do this? all they have to do is check the versions, and add comments to the cs files? – Alex Gordon Nov 10 '17 at 01:41
  • 1
    @l--''''''---------'''''''''''' Because if you put `using System` - how is the plugin supposed to know which specific assembly you're referring to - or what specific package? Granted, it could list all applicable matching versions, but it would be meaningless unnecessary detail - and in *every* source code file? There is no practical use for this data and it ends-up adding clutter and churn. What if a CI/CD system upgrades the package version (say, a minor security update) - it would need to update every client source code file. – Dai Nov 10 '17 at 01:44