[英]How to get the name of a project/solution from a nuget package
Im making a nuget package for work that will be included in some of our projects.我正在为将包含在我们的一些项目中的工作制作一个 nuget 包。 My question is this: Is there a way to get the name of the project that the nuget package will be included in?
我的问题是:有没有办法获取将包含 nuget 包的项目的名称? So far, I've tried this:
到目前为止,我已经尝试过这个:
Assembly.GetCallingAssembly().GetName().Name
but when I run it, that gives me the name of the project in the Nuget package, rather than the name of the project the Nuget package is included in.但是当我运行它时,它给了我 Nuget 包中项目的名称,而不是包含 Nuget 包的项目的名称。
Edit---- The reason I for this is to make a network call to a centralized service from multiple different projects.编辑----我这样做的原因是对来自多个不同项目的集中服务进行网络调用。 Getting the project/solution name will be how the calls are differentiated.
获取项目/解决方案名称将是区分调用的方式。
Using the EntryAssembly works for me from my nuget package.从我的 nuget 包中使用 EntryAssembly 对我有用。
Assembly.GetEntryAssembly().GetName().Name
https://docs.microsoft.com/en-us/dotnet/api/system.reflection.assembly.getentryassembly?view=netcore-3.0 https://docs.microsoft.com/en-us/dotnet/api/system.reflection.assembly.getentryassembly?view=netcore-3.0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.