[英]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. 我需要在我的C#代码中找到
System.dll
的汇编路径,才能在我的代码中使用roslyn执行ac#文件。
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
返回
"C:\\\\WINDOWS\\\\Microsoft.Net\\\\assembly\\\\GAC_MSIL\\\\System.Core\\\\v4.0_4.0.0.0__b77a5c561934e089\\\\System.Core.dll"
,这很棒,因为我需要System.Core.dll
,但我也需要System.dll
But I can't seem to find a type that is contained in System.dll
但我似乎找不到
System.dll
包含的类型
In Visual Studio (2017 at least), right-click on the project reference to System
and then click on 'View in Object Browser'. 在Visual Studio(至少2017)中,右键单击对
System
的项目引用,然后单击“在对象浏览器中查看”。
Try System.Uri
— as it happens, System.dll
doesn't contain what one might reasonably assume it contains. 尝试使用
System.Uri
碰巧的是, System.dll
不包含可能合理假定的内容。 I'm sure there was actual thought went into what goes where. 我敢肯定,实际想法已经深入到了哪里。 Or not.
或不。 For example:
例如:
System.Uri
is an example of a type in the System assembly. System.Uri
是System程序集中类型的示例。
Quick PowerShell confirmation: 快速PowerShell确认:
[System.Uri].Assembly.Location
您需要使用typeof(Enumerable).Assembly.GetReferencedAssemblies()
及其依赖项等来遍历依赖项树...
You can use dotPeek. 您可以使用dotPeek。 It's free and you can see metadata of a dll file.
它是免费的,您可以看到dll文件的元数据。 Screenshot from dotPeek
dotPeek的屏幕截图
Now you can see that you can use for example FileStyleUriParser
. 现在您可以看到可以使用例如
FileStyleUriParser
。
var path = typeof(FileStyleUriParser).Assembly.Location;
And voila, you have path to System.dll. 瞧,您拥有System.dll的路径。
Also you can use Visual Studio object browser. 您也可以使用Visual Studio对象浏览器。
View -> Object Browser
or Ctrl + Alt + J
and you achieve that same result. View -> Object Browser
或Ctrl + Alt + J
,您将获得相同的结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.