-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Accessing class library's content files #18159
Comments
This is partially an SDK issue question, so also tagging @dsplaisted. |
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
The SDK copies the content file from the library project to the output folder for the runner. I think the issue is that when you build a web app but don't publish it, the ContentRootPath is the source root of the project file, not its output path. Is this correct? If so, I'm not sure what the solution is. Maybe web projects should have a setting where they use the output folder instead of the project file folder (ie skipping the optimization where they don't need to copy content files to the output folder)? |
@Pilchie, @dsplaisted - you're correct that it is an SDK issue, sorry for putting it in the wrong place; The main issue is that the behaviour between The Perhaps we should first answer the question regarding "bin path" (i.e. |
@skyflyer Don't worry too much about filing in the exact right repo, we have a lot of them and it's not always obvious where the root cause of an issue is. We'll try to move them as appropriate. :-) |
|
So, @javiercn, you're essentially saying that |
What is the correct approach in accessing a class library's (not Razor class library!) content files?
For the purpose of this discussion and demonstration, let's have a class library
C1
and a simple web app calledRunner
.The
C1
library contains a fileAssets/template.txt
that it uses at runtime. This could also be some other binary file that the library uses for its functionality, but let's say that this is not a static web asset (for which the solution exists in the Razor class library).This library is used in the project
Runner
. Since the library defines that theAssets/template.txt
is copied to output directory and is copied to publish directory, it is possible to access theAssets/template.txt
by usingIHostEnviornment.ContentRootPath
and appendAssets/template.txt
to it. This only works if youdontet publish
the Runner application and run the published binary, but does not work if youdotnet run
the runner.The reason, as I understand, is there is only one
IHostEnvironment
and so there can be only one ContentRootPath... so accessing the files in the individual class library can be done by using a "workaround":The question here is, if this is the correct way to access to these files or is there a better way?
The runnable short demo is provided here: demo.zip
If you
dontet publish -o out
andcd out
anddotnet Runner.dll
, you will se that it is working, sinceAssets
folder will be present there. If you justdotnet run
it, theAssets/template.txt
will not be resolved correctly.I know there is also the option of EmbeddedResources, but that breaks some other library I'm using which wants to access certain files via regular file system APIs.
The text was updated successfully, but these errors were encountered: