0

I'm starting from the asp.net core with angular template for visual studio. This sets up a single angular app in the ClientApp directory and handles serving the angular app from npm during development and routing requests to the dist directory when deployed.

It works correctly with the single angular app, however, when I add a second angular app and attempt to duplicate the relevant sections of the csproj for the second app, visual studio seems to lose track of where the tsconfig files are (or something else perhaps...) and neither angular app will build and I get many typescript errors for both apps.

The relevant lines (as far as I understand) are:

<PropertyGroup>
    ...
    <SpaRoot>testApp\</SpaRoot>
    <Spa2Root>SecondApp\</Spa2Root>
    <DefaultItemExcludes>$(DefaultItemExcludes);$(SpaRoot)node_modules\**;$(Spa2Root)node_modules\** 
    </DefaultItemExcludes>
</PropertyGroup>
...
<ItemGroup>
    <!-- Don't publish the SPA source files, but do show them in the project files list -->
    <Content Remove="$(SpaRoot)**" />
    <None Remove="$(SpaRoot)**" />
    <None Include="$(SpaRoot)**" Exclude="$(SpaRoot)node_modules\**" />    
</ItemGroup>
<ItemGroup>
    <Content Remove="$(Spa2Root)**" />
    <None Remove="$(Spa2Root)**" />
    <None Include="$(Spa2Root)**" Exclude="$(Spa2Root)node_modules\**" />
</ItemGroup>
...

There are other lines which reference "Spa2Root" but they dont seem to affect the outcome.

If I simply remove the second "ItemGroup" all is well once again and the app serves correctly in development and publish mostly works. The issue is that I get all the config json files from "SecondApp" copied to the published directory (because the second item group takes care of making sure they dont end up there).

This obviously isnt the end of the world, but its also not correct and I'm wondering what I'm missing here.

Mason
  • 737
  • 2
  • 9
  • 23
  • Hello, I am curious about this, why do you need 2 Angular's Apps in a single .net project? When you can have the 2nd app to be a sub module of the first app. I would love to know this scenario. Thank you – J. B Apr 30 '20 at 20:38
  • I do not currently have a use case, I'm just trying to evaluate the capability. Here are a few other SO questions from users who also want to host multiple angular apps with brief use case descriptions https://stackoverflow.com/questions/56482398/how-to-handle-multiple-spa-application-in-asp-net-core https://stackoverflow.com/questions/48216929/how-to-configure-asp-net-core-server-routing-for-multiple-spas-hosted-with-spase – Mason Apr 30 '20 at 20:56
  • I am trying to do the same thing: have two apps in one project. The apps are unrelated but I want to structure the project like this to share code between them. – chenny Jul 05 '23 at 06:28

0 Answers0