ssdug / CVPZ

GNU General Public License v3.0
16 stars 18 forks source link

Create .Net Core web project #2

Closed CarBar closed 7 years ago

CarBar commented 7 years ago

There is an issue with serving css and js files when we run this in vscode. However it works fine running from the command line with dotnet run. The following worked for me.

http://stackoverflow.com/questions/39860484/getting-404-for-css-and-js-assets-in-kestrel-while-debugging-in-visual-studio-co

CarBar commented 7 years ago

After looking into the solution provided for Core and Angular 2 on this site => http://asp.net-hacker.rocks/2016/09/19/aspnetcore-and-angular2-using-dotnetcli-and-vscode.html I found a different direction in solving one of the problems that it had on Sandersons blog, so I am revising and going to follow... http://blog.stevensanderson.com/2016/10/04/angular2-template-for-visual-studio/

strikekat commented 7 years ago

There is an issue with serving css and js files when we run this in vscode. However it works fine running from the command line with dotnet run. The following worked for me.

The reason it doesn't work from VS Code is because there is no lib directory for the site to pull assets from. You can resolve this by running bower install in the project directory or dotnet publish, as that script includes a bower install (see project.json). You could also add that as a launch task for VS Code, but I don't know the toolchain enough to say exactly how.

I think the reason that it works when running entirely through terminal with dotnet, is because ASPNETCORE_ENVIRONMENT env variable is never getting set to Development, while VS Code is setting this in launch.json:

"env": {
    "ASPNETCORE_ENVIRONMENT": "Development"
}

This affects what assets are fetched.. See the following in _Layout.cshtml:

<environment names="Development">
    <script src="~/lib/jquery/dist/jquery.js"></script>
    <script src="~/lib/bootstrap/dist/js/bootstrap.js"></script>
    <script src="~/js/site.js" asp-append-version="true"></script>
</environment>
<environment names="Staging,Production">
    <script src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-2.2.3.min.js"
            asp-fallback-src="~/lib/jquery/dist/jquery.min.js"
            asp-fallback-test="window.jQuery">
    </script>
    <script src="https://ajax.aspnetcdn.com/ajax/bootstrap/3.3.6/bootstrap.min.js"
            asp-fallback-src="~/lib/bootstrap/dist/js/bootstrap.min.js"
            asp-fallback-test="window.jQuery && window.jQuery.fn && window.jQuery.fn.modal">
    </script>
    <script src="~/js/site.min.js" asp-append-version="true"></script>
</environment>

Anyways, hopefully that explains what was going on there.

CarBar commented 7 years ago

After creating a CVPZ.Web project from the templates in the ASP.NET Core Templates, I believe this issue is closed.

CarBar commented 7 years ago

Per conversation with @bivvo I am thinking that we should completely separate our Angular2 side from our .Net Core Api. I think this would be both a good exercise and make our docker solution more interesting.

CarBar commented 7 years ago

Initial web project and .net core projects are in place.