Aurelia CLI Run Command in ASP.NET Core Project Producing Only CannotGET - asp.net-core

I have created a new ASP.NET Core Web API project and then run the au new --here command selecting option 2 (ASP.NET Core Project) to create a starting point for a web application.
Next I updated the Startup.cs file to serve static files.
app.UseDefaultFiles();
app.UseStaticFiles();
app.UseFileServer();
Finally I updated the aurelia.json file to build into the wwwroot folder.
"platform": {
"id": "aspnetcore",
"displayName": "ASP.NET Core",
"output": "wwwroot/scripts",
"index": "wwwroot/index.html",
"baseUrl": "scripts"
},
"build": {
"targets": [
{
"id": "aspnetcore",
"displayName": "ASP.NET Core",
"output": "wwwroot/scripts",
"index": "wwwroot/index.html",
"baseUrl": "scripts"
}
],
The Aurelia CLI will run the build option (au build) and the run option (au run) fine and it will serve up the site on http://localhost:9000. But I get only the following HTML served up:
<html><head></head><body>CannotGET /</body></html>
or if trying to reference http://localhost:9000/index.html
<html><head></head><body>CannotGET /index.html</body></html>
If I run the application through Visual Studio and IIS Express it works fine.
What am I missing to get au run to work?
I have the same result with ASP.NET Core 1.0, 1.1 and in Visual Studio 2015 and Visual Studio 2017. If I use au new without the --here and no ASP.NET Core integration au run will work just fine.

I found the answer buried in an issue on GitHub: https://github.com/aurelia/cli/issues/405
The run.js file need to also have the path updated.
baseDir: ['./wwwroot'],

Related

Can Blazor Server in Visual Studio hosted via Kestrel (not IIS Express) support automatic rebuild on Razor file change?

I'm using VS 2019, .NET 5 and Blazor server projects.
I always liked the plain Kestrel better than IIS Express when developing in VS 2019. It feels faster and I get the dedicated console window to show logs etc instead of relying on VS's output window. So every time I start a new project I usually switch from the default IIS Express to Kestrel via launchsettings.json.
However, I noticed that with IIS Express, Blazor server projects would auto re-build whenever a changed Razor file is saved. I do not see the same behavior after switching to Kestrel host.
Is there any way to make it work the same way as IIS Express for auto rebuild?
I see something about the dotnet watch, but I usually just launch quickly via Ctrl + F5 etc and it would be a pain to have to use command line every time to start the project.
You can use dotnet watch - and have Ctrl-F5 work, by adding a new profile to launchsettings.json in your project. You can select "Watch" in the toolbar as the profile, then press Ctrl+F5 to launch it.
"Watch": {
"commandName": "Executable",
"dotnetRunMessages": "true",
"workingDirectory": "$(ProjectDir)",
"executablePath": "dotnet.exe",
"commandLineArgs": "watch",
"applicationUrl": "https://localhost:5000;http://localhost:5001",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
And when you move to .NET 6 with hot reload, you can use this:
"HotReload": {
"commandName": "Executable",
"dotnetRunMessages": "true",
"workingDirectory": "$(ProjectDir)",
"executablePath": "dotnet.exe",
"commandLineArgs": "watch",
"hotReloadProfile": "aspnetcore",
"applicationUrl": "https://localhost:5000;http://localhost:5001",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
Found the setting:
VS Options -> Projects and Solutions -> ASP.NET Core -> Auto build and refresh option
Change to "Auto build and refresh browser after saving changes".

Lauching dotnet fails ("dotnet" is not a file of a symlink)

The default vscode configuration for debugging ASP.NET core contains the following:
"configurations": [
{
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
...
The preLaunchTask fails for me with the following error:
The terminal process failed to launch: Path to shell executable "dotnet" is not a file of a symlink.
I have had this problem before, not on the preLaunchTask but on the main program execution. That I could work around by doing a replace all "dotnet" -> "/usr/bin/dotnet" in ~/.vscode/extensions/ms-dotnettools.csharp-1.**.*/dist/extensions.js + a vscode restart. However, this workaround doesn't work for the preLaunchTask. (And having to do this for every update of that extension in annoying).
Given that I'm a linux noob, it's probably not omnisharp/vscode related but could be something I did wrong in Ubuntu 18.04.
Does anybody know what the error means, and how to fix it? Or even how to debug this problem?
I've already reinstalled vscode, .net5, and my global $PATH env does contain /home/<username>/.dotnet/tools:/usr/bin/dotnet. Other than that I don't know what to do.
in tasks.json file change from
"type": "process" to "type": "shell"

TFS 2015 build error

I need help with my TFS 2015, I able to run build and publish in Visual Studio 2015 and when I create a build it in TFS 2015, my jquery is not completely built.
my setup in Command Line
Tool : C:\Windows\ServiceProfiles\NetworkService\AppData\Roaming\npm\bower.cmd
Arguments : install jquery
Build log
Everything works fine except the jquery only a few files and folders were created compared to build from in VS 2015.
Please let me know where I did wrongly.
Try the solution in this case ECONFLICT Unable to find suitable version for jquery Foundation:
Use resolutions in your bower.json file. For example:
{
"name": "refactor",
"private": true,
"dependencies": {
"jquery": "~1.11.1",
"raphael": "1.3.x",
"font-awesome": "~4.3.0",
"foundation": "x"
},
"resolutions": {
"jquery": "~1.11.1"
}
}
This will force bower to use that specific version of jQuery.

Aurelia and webpack during dotnet publish in ASP.NET Core 2.0 and Visual Studio 2017

The ASP.NET Core 2.0 project brings in Aurelia using
au new --here
I want to create the following artefacts when publishing the solution
\wwwroot\dist\app.bundle.js
\wwwroot\dist\vendor.bundle.js
I can achieve this by manually running
npx webpack --config webpack.netcore.config.js
But I would like to kickoff webpack builds when I publish:
dotnet publish -c Release
My ultimate aim is to have VSTS CI/CD process use MSBuild to automatically bundle the SPA files as required above.
Please note, during development I am already using hot module replacement via
using Microsoft.AspNetCore.SpaServices.Webpack;
And
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions
{
HotModuleReplacement = true,
ConfigFile="webpack.netcore.config.js",
HotModuleReplacementClientOptions = new Dictionary<string,string>{
{"reload", "true"}
}
});
}
This works as expected. But now I need to achieve the same during publishing.
As a quick fix I've added a post-build event
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="npx webpack --config webpack.netcore.config.js" />
</Target>
How do I get the custom MSBuild RunWebpack target explained here?
So I also ran into the same issue. I noticed that in the webpack.config.js file it had the following lines:
output: {
path: outDir,
publicPath: baseUrl,
filename: production ? '[name].[chunkhash].bundle.js' : '[name].[hash].bundle.js',
sourceMapFilename: production ? '[name].[chunkhash].bundle.map' : '[name].[hash].bundle.map',
chunkFilename: production ? '[name].[chunkhash].chunk.js' : '[name].[hash].chunk.js'
},
But in the webpack.netcore.config.js file it had:
config.output.filename = '[name].bundle.js';
So when you publish it, it expects .net core to copy the app.bundle.js and vendor.bundle.js files but they aren't there, because webpack has it under a different file name due to caching purposes.
So replace that line with the following:
config.output.filename = '[name].[chunkhash].bundle.js';

Is VSC not compatible with .net core 2 projects?

Environment: Ubuntu 16.04, .NET Core SDK Preview 2.0.0 (006497), VSC 1.14.2
Things used to work fine under .net core 1. Now, I have upgraded my system to .net core 2.
From the command line, I created a new project and ran it:
$ dotnet new mvc
$ dotnet run
The webpage works as expected.
Now, I open the folder in VSC and tried to debug the app. First time, VCS helps create launch.json and tasks.json. Here is my tasks.json contents:
"version": "2.0.0",
"tasks": [
{
"taskName": "build",
"command": "dotnet",
"type": "shell",
"group": "build",
"presentation": {
"reveal": "silent"
},
"problemMatcher": "$msCompile"
}
]
}
In the terminal view, I see that VCS tries to run the build command as dotnet <. This throws an error that preLaunchTask "build" exited with error code 129.
I tried to fix this by adding args: ["build"] to the task. This seems to fix the build but I now get another error about launch.json not being configured properly.
Wondering if there is some step that I simply missed. Regards.
The answer was provided by mvermef in his comment. I am just adding a new post here so I can mark it as an answer.
The problems with VSC are explained at https://github.com/dotnet/core/blob/master/release-notes/2.0/2.0.0-preview2-known-issues.md. The most important thing is that you remove your existing C# extension and replace it with the latest beta version. Now, if you create a new project from the command line and load it in VSC, you should be able to debug it.