Chris
Chris

Reputation: 45

dotnet run won't use bower packages

I have an asp.net core web application I'm trying to get running in a Docker container.

From powershell, inside the project file, I can run > dotnet restore then > dotnet run and it will run a docker container:

PS E:\Projects\...> dotnet run
Project MyProject (.NETCoreApp,Version=v1.1) was previously compiled. Skipping compilation.
Hosting environment: Production
Content root path: E:\Projects\...
Now listening on: http://localhost:5000
Application started. Press Ctrl+C to shut down.

The only issue is that when I go to localhost:5000, it appears like the bower packages (like Angular) aren't installed. While the webpages/controllers all work, the front end Angular won't run.

It doesn't return a 404 not found, it just doesn't bind any of the Angular stuff.

If I run the same project from Visual Studio (2015) it includes/runs Angular with no worries, and the website looks like it should. Viewing the source, you can see that the angular files have been included.

My DockerFile is:

FROM microsoft/aspnetcore-build
WORKDIR /app
COPY published .
ENTRYPOINT ["dotnet", "MyProject.dll"]

but I think it's an issue with the dotnet run command.

How can I ensure the bower packages are included and run inside the docker container?


Edit 1

I tried doing dotnet build then bower install then dotnet run with no luck.

After that I tried to publish it wtih dotnet publish -o published and then ran it with dotnet MyProject.dll from the published directory and it did the same thing.

When I run the project from Visual Studio the page has all the scripts included:

...
<script src="/lib/jquery/dist/jquery.js"></script>
<script src="/lib/jquery-validation/dist/jquery.validate.js"></script>
<script src="/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.js"></script>
<script src="/lib/bootstrap/dist/js/bootstrap.js"></script>
<script src="/js/site.js?v=EWaMeWsJBYWmL2g_KkgXZQ5nPe-a3Ichp0LEgzXczKo"></script>
<script src="/lib/angular/angular.js?v=IuVz88ct2cRJMIP8PVY9rcWTcd2eXzzvz3cdkmfoX2k"></script>
...

But when I run it using both dotnet run and dotnet publish then dotnet MyProject.dll those scripts aren't included in the page source.


Fixed

Turns out that I was running dotnet run, which meant it was running in Production mode.

There's a file in the views Views\Shared\Components\_EnvironmentFooter.cshtml which is where all the scripts are included for the page. The only issue was that the scripts were included in the Development environment, but not the Production environment.

<environment names="Development">
    <script src="~/lib/jquery/dist/jquery.js"></script>
    <script src="~/lib/jquery-validation/dist/jquery.validate.js"></script>    
    <script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.js"></script>
    <script src="~/lib/bootstrap/dist/js/bootstrap.js"></script>
    <script src="~/js/site.js" asp-append-version="true"></script>
    <script src="~/lib/angular/angular.js" asp-append-version="true"></script>
</environment>
<environment names="Staging,Production">
    <script src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-2.2.0.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>

I included the scripts from development in Production/Staging environment - No longer an issue.

Upvotes: 0

Views: 410

Answers (2)

Chris
Chris

Reputation: 45

Turns out I was not adding the scripts from bower to the production code. See edit above.

Upvotes: 0

Tim
Tim

Reputation: 6060

Bower dependencies are typically handled by dotnet publish based on the scripts element of project.json. If you don't want to run dotnet publish, try running bower install between dotnet restore and dotnet run.

Upvotes: 1

Related Questions