I figured this should be a no-brainer but It's caused me hours of headaches already. I have a simple Razor Class Library (RCL) including a page containing some JavaScript.
@page
@*...*@
<h1>Test Page</h1>
@section Scripts {
<script type="text/javascript" src="~/lib/somejs.js"></script>
<script type="text/javascript">
console.log("log something"); // works
let something = new SomeJS("hello World");
</script>
}
I also have a _Layout.cshtml containing @RenderSection("scripts", required: false) to allow the conditional include of the script-tag.
The given script is included, but despite the reference to ~/lib/somejs.js there is the following error occurring:
https://localhost:44385/lib/somejs.js net::ERR_ABORTED 404
The required file is inside the RCL's wwwroot/lib folder. It seems to me that the given path is wrong as it expects the files at non-existent folder inside the actual web project rather than the RCL.
How can i resolve the reference correctly from within the RCL? Ideally, the project using it does not have to bother about including them manually.
EDIT: Even inserting the hardcoded path suggested by Visual Studio does not resolve the issue, e.g. src="../../wwwroot/lib/some.js".