The issue you are seeing is that when you start the webhost with the other app, it's using the other apps location as it's root. So, here is starting the service normally:

Here it is starting it with the console application:

So what's happening is when you add ExternalLoginTest
as a dependency to SelfHostedConsoleApp
, the compiler now moves ExternalLoginTest
module in to SelfHostedConsoleApp
's directory essentially breaking your paths.
Step 1: Copy over wwwroot directory
So the challenge here is that we have to move the wwwroot
to the new destination. I see you tried that in your question, but it needs to be like this:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Content Include="wwwroot\**" Link="wwwroot\%(RecursiveDir)%(Filename)%(Extension)"
CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
</Project>
This is going to create a symbolic link back to the wwwroot
directory in the host project.
Step 2: EnableDefaultContentItems option set to false
When you do this, you will see all kinds of errors and something about adding EnableDefaultContentItems
to false. So let's go ahead and do that:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<EnableDefaultContentItems>false</EnableDefaultContentItems>
</PropertyGroup>
<ItemGroup>
<Content Include="wwwroot\**" Link="wwwroot\%(RecursiveDir)%(Filename)%(Extension)"
CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
</Project>
If we run it now, it's going to return a 404. But, to prove static content is working, try going to http://localhost:5000/favicon.ico
and it will show you the static content.
Step 3: Add your razor pages as Content
The reason why it is now returning 404 is because none of your razor pages are marked as Content
so the framework thinks you have no pages to display. The only major drawback to using EnableDefaultContentItems
set to false
is we have to manually add your razor pages to your .csproj
files. Visual Studio won't do it for us any more. So, now your project file will look like this:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<EnableDefaultContentItems>false</EnableDefaultContentItems>
</PropertyGroup>
<ItemGroup>
<Content Include="wwwroot\**" Link="wwwroot\%(RecursiveDir)%(Filename)%(Extension)"
CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
<ItemGroup>
<Content Include="Pages\Error.cshtml" />
<Content Include="Pages\Index.cshtml" />
<Content Include="Pages\Privacy.cshtml" />
<Content Include="Pages\Shared\_Layout.cshtml" />
<Content Include="Pages\Shared\_ValidationScriptsPartial.cshtml" />
<Content Include="Pages\_ViewImports.cshtml" />
<Content Include="Pages\_ViewStart.cshtml" />
</ItemGroup>
</Project>
A shortcut to doing this is to shift-click on your pages, right-click and do "properties" then in the property window change Build Action
to Content
.
Step 4: Run!
At this point we should be 100%:
