简体   繁体   中英

C# How do I get the path to the System assembly

I need to find the assembly path of System.dll in my c# code to execute ac# file with roslyn in my code.

typeof(Enumerable).Assembly.Location

Returns "C:\\\\WINDOWS\\\\Microsoft.Net\\\\assembly\\\\GAC_MSIL\\\\System.Core\\\\v4.0_4.0.0.0__b77a5c561934e089\\\\System.Core.dll" which is great because I need the System.Core.dll , but I also need System.dll

But I can't seem to find a type that is contained in System.dll

In Visual Studio (2017 at least), right-click on the project reference to System and then click on 'View in Object Browser'.

Try System.Uri — as it happens, System.dll doesn't contain what one might reasonably assume it contains. I'm sure there was actual thought went into what goes where. Or not. For example:

System.dll内容

System.Uri is an example of a type in the System assembly.

Quick PowerShell confirmation:

[System.Uri].Assembly.Location

您需要使用typeof(Enumerable).Assembly.GetReferencedAssemblies()及其依赖项等来遍历依赖项树...

You can use dotPeek. It's free and you can see metadata of a dll file. Screenshot from dotPeek

Now you can see that you can use for example FileStyleUriParser .

var path = typeof(FileStyleUriParser).Assembly.Location;

And voila, you have path to System.dll.

Also you can use Visual Studio object browser. View -> Object Browser or Ctrl + Alt + J and you achieve that same result.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM