dotnet build - get error "could not return the default page '/index.html'"

dotnet build version
dotnet build multiple projects
dotnet build exclude project
dotnet test
dotnet build nuget
dotnet build tools
dotnet build vs msbuild
how to build .net application

try to generate my project into exe file, but get error:

before: "dotnet build -r win10-x86" is ok

after run generated exe, all is ok also:

indows DPAPI to encrypt keys at rest.
Hosting environment: Production
Content root path: C:....\currencyColution\correncyProject\bin\Debug\netcoreapp2.1\win10-x86
Now listening on: http://localhost:5000
Now listening on: https://localhost:5001
Application started. Press Ctrl+C to shut down.

after load page is somwthing worng, more precisely index.html is not found:

info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
      Request starting HTTP/1.1 GET http://localhost:5000/
fail: Microsoft.AspNetCore.Server.Kestrel[13]
      Connection id "0HLG91TC2H0UO", Request id "0HLG91TC2H0UO:00000001": An 

unhandled exception was thrown by the application.
System.InvalidOperationException: The SPA default page middleware could not return the default page '/index.html' because it was not found, and no other middleware handled the request.
Your application is running in Production mode, so make sure it has been published, or that you have built your SPA manually. Alternatively you may wish to switch to the Development environment.

Startup.cs

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.SpaServices.AngularCli;
using Microsoft.Extensions.DependencyInjection;
using Swashbuckle.AspNetCore.Swagger;
using System;
using System.IO;
using Microsoft.AspNetCore.Http;

namespace AspNetCore2Ang6Template
{
  public class Startup
  {

    public void ConfigureServices(IServiceCollection services)
    {
      services.AddMvc();
      services.AddSpaStaticFiles(c =>
      {
        c.RootPath = "wwwroot";
      });

    }

    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
      if (env.IsDevelopment())
      {
        app.UseDeveloperExceptionPage();
      }

      app.UseDefaultFiles();
      app.UseStaticFiles();
      app.UseSpaStaticFiles();
      app.UseMvc(routes =>
      {
        routes.MapRoute(name: "default", template: "{controller}/{action=index}/{id}");
      });

      app.UseSpa(spa =>
      {
        spa.Options.SourcePath = "wwwroot";
      });

    }
  }
}

I dont't use angular and some other ones, just try to open wwwroot/index.html

files:

currencyProject

wwwroot

Program.cs

Startup.cs

Tested in VS , all works, but not via exe builder

launched like dev : dotnet run, then it works on localhost:58893/, but what is wrong with prod dotnet build on localhost:5000

launchSettings:

{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:58842/",
      "sslPort": 0
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "AspNetCore2Ang6Template": {
      "commandName": "Project",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "applicationUrl": "http://localhost:58893/"
    }
  }
}

The problem come from the fact when you build the project with the command dotnet build, the wwwroot folder is not copied.

I reproduced your problem, to fix it, I copied the folder in the output and it worked.

You should use the publish command to test production.

In either cases, both commands don't copy the wwwroot folder.

Here is a fix: https://github.com/aspnet/websdk/issues/114

No matter what kind of error I introduce, the only output I get is. C:\Program Files\​dotnet\sdk\2.0.0\Roslyn\Microsoft.CSharp.Core.targets(84,5):  dotnet build uses MSBuild to build the project, so it supports both parallel and incremental builds. For more information, see Incremental Builds. In addition to its options, the dotnet build command accepts MSBuild options, such as -p for setting properties or -l to define a logger.

check angular.json file use "outputPath": "dist",

And Startup file

 services.AddSpaStaticFiles(configuration =>
      {
        configuration.RootPath = "ClientApp/dist";
      });

dotnet_stage0/Linux/dotnet build_projects/dotnet-host-build/ build Object reference not set to an instance of an object. I just get a one-line error  @alexvkru Thanks for the prompt response and the log - I appreciate it.. Is there a chance you could reproduce this problem on an English language system, or set your UI locale to English and reproduce the problem again so that the msbuild logs are generated in English?

Resolved this issue by comparing existing Angular Asp net core template, I did following code changes.

In csproj file:

<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
 <TypeScriptToolsVersion>Latest</TypeScriptToolsVersion>
 <IsPackable>false</IsPackable>
 <SpaRoot>ClientApp\</SpaRoot>
 <DefaultItemExcludes>$(DefaultItemExcludes);$(SpaRoot)node_modules\**</DefaultItemExcludes>

 <!-- Set this to true if you enable server-side prerendering -->
 <BuildServerSideRenderer>false</BuildServerSideRenderer>
 <UserSecretsId>baa2f579-d2a7-4eb4-89fb-1c171b2e2482</UserSecretsId>
 <TypeScriptToolsVersion>3.0</TypeScriptToolsVersion>

<ItemGroup>
 <TypeScriptCompile Include="App\src\app\models\user.ts" />
 <TypeScriptCompile Include="App\src\app\utils\AppContants.ts" />
 <!-- Don't publish the SPA source files, but do show them in the project files list -->
 <Content Remove="$(SpaRoot)**" />
 <None Include="$(SpaRoot)**" Exclude="$(SpaRoot)node_modules\**" />
</ItemGroup>

<ItemGroup>
 <Folder Include="Properties\PublishProfiles\" />
</ItemGroup>

<Target Name="DebugEnsureNodeEnv" BeforeTargets="Build" Condition=" '$(Configuration)' == 'Debug' And !Exists('$(SpaRoot)node_modules') ">
 <!-- Ensure Node.js is installed -->
 <Exec Command="node --version" ContinueOnError="true">
   <Output TaskParameter="ExitCode" PropertyName="ErrorCode" />
 </Exec>
 <Error Condition="'$(ErrorCode)' != '0'" Text="Node.js is required to build and run this project. To continue, please install Node.js from https://nodejs.org/, and then restart your command prompt or IDE." />
 <Message Importance="high" Text="Restoring dependencies using 'npm'. This may take several minutes..." />
 <Exec WorkingDirectory="$(SpaRoot)" Command="npm install" />
</Target>

<Target Name="PublishRunWebpack" AfterTargets="ComputeFilesToPublish">
 <!-- As part of publishing, ensure the JS resources are freshly built in production mode -->
 <Exec WorkingDirectory="$(SpaRoot)" Command="npm install" />
 <Exec WorkingDirectory="$(SpaRoot)" Command="ng build --prod" />
 <Exec WorkingDirectory="$(SpaRoot)" Command="npm run build:ssr -- --prod" Condition=" '$(BuildServerSideRenderer)' == 'true' " />

 <!-- Include the newly-built files in the publish output -->
 <ItemGroup>
   <DistFiles Include="$(SpaRoot)dist\**; $(SpaRoot)dist-server\**" />
   <DistFiles Include="$(SpaRoot)node_modules\**" Condition="'$(BuildServerSideRenderer)' == 'true'" />
   <ResolvedFileToPublish Include="@(DistFiles->'%(FullPath)')" Exclude="@(ResolvedFileToPublish)">
     <RelativePath>%(DistFiles.Identity)</RelativePath>
     <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
   </ResolvedFileToPublish>
 </ItemGroup>
</Target>

In Startup.cs

services.AddSpaStaticFiles(configuration =>
            {
                configuration.RootPath = "ClientApp/dist";
            });

 app.UseSpa(spa =>
            {
                spa.Options.SourcePath = "ClientApp";
                if (env.IsDevelopment())
                {
                    spa.UseAngularCliServer(npmScript: "start");
                }
            });

In Angular Package.json

 "options": {
    "outputPath": "dist",

Steps to reproduce We are using dotnet build -warnaserror and StyleCop as part of you CI which run in Docker. I haven't been able to  Steps to reproduce I have a ASP.Net Core 2 web application with class libraries that target the .net 4.7 framework. Visual Studio compiles fine but dotnet build fails. I&#39;ve tracked the errors d

But on dotnet build I always get the error "Couldn't find 'project.json' in current directory". I have a very basic program and structure: root |-TestApp | |-TestApp.​sln |  From @gdillen on Tuesday, January 29, 2019 3:56:08 PM Steps to reproduce I&#39;m on macOS 10.14.2 dotnet version 2.2.103 Create a C# class library project Add package metadata to the project file i

by regex 'dotnet-sdk-2.1' The command "sudo apt-get install -qq dotnet-sdk-2.1​=2.1.502*" failed and exited with 100 during . Your build has  dotnet run. dotnet run calls dotnet build to ensure that the build targets have been built, and then calls dotnet <assembly.dll> to run the target application. dotnet run You get the following output. Hello World! Alternatively, you can also run dotnet build to compile the code without running the build console applications. This results in a compiled application, as a DLL file, based on the name of the project.

I keep getting various build errors regarding dotnet dependencies. the latest is AspNetCore.OData. Any ideas how to troubleshoot? dotnet build: Builds a .NET Core application. dotnet build-server: Interacts with servers started by a build. dotnet clean: Clean build outputs. dotnet help: Shows more detailed documentation online for the command. dotnet migrate: Migrates a valid Preview 2 project to a .NET Core SDK 1.0 project. dotnet msbuild: Provides access to the MSBuild command line.

Comments
  • I tried to do the same, it is working for me. How do you launch the exe ? Any param added or smth ? Which version of .Net are you using ?
  • @Zysce, Microsoft.AspNetCore.All 2.1.2, Microsoft.AspNetCore.SpaServices 2.1.1, exe launched as Admin and User, without any params
  • @Zysce, maybe Port, 5000, 5001 set exe builder, but via IDE port is 58843 and it works
  • @Zysce, I use Windows 10 on VMware Fusion, dotnet 2.1.4
  • @Zysce, launched like dev : dotnet run, then it works on localhost:58893/, but what is wrong with prod dotnet build on localhost:5000
  • I think you mean angular.json not package.json. I'm surprised though since you're using SSR. Wouldn't your outputPath need to be "dist/browser"? Which section of your package.json did you alter?