简体   繁体   English

如何从 nuget 包中获取项目/解决方案的名称

[英]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.

相关问题 如何从 Visual Studio Package 项目中获取当前的解决方案名称? - How to get the current solution name from a Visual Studio Package project? 如何通过构建将nuget包添加到项目(不是解决方案) - How to add nuget package to project (not solution) with build 如何为解决方案中的每个项目创建单独的 nuget 包,并将项目引用转换为 nuget 依赖项? - How do I create an individual nuget package for each project in a solution, with project references converted to nuget dependencies? 通过Nuget包在解决方案中创建新项目 - Creating a new project in a Solution through Nuget package 是否可以在解决方案中为单个项目创建Nuget包? - Is it Possible to Create Nuget Package for Single Project in a Solution? 如何让 NuGet 包为从另一个解决方案添加的现有项目正确恢复? - How to get NuGet packages to restore correctly for an existing project added from another solution? 如何在从 DevOps 提取的解决方案中使用 DevOps nuget package - How to use DevOps nuget package in solution pulled from DevOps 如何从私有NuGet提要中获取NuGet包的依赖项? - How to get the dependencies of a NuGet package from private NuGet feed? 如何在另一个解决方案中还原自己的nuget软件包 - How to restore own nuget package in another solution 引用 a.Net Core 3.1 NuGet package 的 a.Net 5 Visual Studio 项目/解决方案如何编译成功? - How can a .Net 5 Visual Studio Project / Solution that reference a .Net Core 3.1 NuGet package compile successfuly?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM