3

Im making a nuget package for work that will be included in some of our projects. My question is this: Is there a way to get the name of the project that the nuget package will be included in? 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.

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.

itcropper
  • 752
  • 1
  • 7
  • 21
  • 1
    Why do you need this? Nuget supports [templated code files](https://learn.microsoft.com/en-us/nuget/create-packages/source-and-config-file-transformations) that might work for some scenarios. What are you trying to achieve? – RB. Jan 31 '17 at 22:55
  • maybe require the main project where the package is loaded to pass an identifying parameter when the class that makes the network call is instantiated? Or require it to put an item in the .config file that you can read. Sounds like you're kind of trying to do this backwards. – ADyson Jan 31 '17 at 23:01
  • Search StackOverflow for answers. http://stackoverflow.com/questions/11014280/c-sharp-getting-parent-assembly-name-of-calling-assembly – stevieg Jan 31 '17 at 23:50

1 Answers1

3

Using the EntryAssembly works for me from my nuget package.

Assembly.GetEntryAssembly().GetName().Name

https://learn.microsoft.com/en-us/dotnet/api/system.reflection.assembly.getentryassembly?view=netcore-3.0

Robert Columbia
  • 6,313
  • 15
  • 32
  • 40
HectorE
  • 31
  • 2