Reputation:
We have a API Real Application which is running following code to get the Assembly Directory.
Assembly.GetEntryAssembly().Location
Result:
C:\\OriginalApplicationAPI\\bin\\Debug\\netcoreapp2.2
Now we are running an Integration Xunit project, which is running the Startup, appsettings, etc from the original project.
Running this code from the Integration test project renders,
C:\\Users\\..\\.nuget\\packages\\microsoft.testplatform.testhost\\15.9.0\\lib\\netstandard1.5"
How do I refer to the OriginalApplicationAPI Assembly Location from test project? Is it by namespace or project reference?
Thanks,
Upvotes: 3
Views: 1840
Reputation: 8672
You will need to know of a Type that is in the assembly.
Let's say App.MyClass
is defined in the assembly. You can use reflection to get the location of the assembly containing that type:
Assembly.GetAssembly(typeof(App.MyClass)).Location.
You can't do it using a namespace as a namespace can exist across multiple assemblies.
Or utilize
Assembly.GetExecutingAssembly().Location
Upvotes: 3