我有一個由 ASP.NET 應用程式管理的 Angular 應用程式,如教程中所示。在開發環境中,我可以dotnet run從 ASP.NET 的專案目錄中進行操作。然后構建專案和輸出
info: Microsoft.Hosting.Lifetime[14]
Now listening on: https://localhost:5273
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: production
info: Microsoft.Hosting.Lifetime[0]
Content root path: C:\Dev\MyApp\src\MyApp.Client\
info: Microsoft.AspNetCore.SpaProxy.SpaProxyLaunchManager[0]
No SPA development server running at https://localhost:44459 found.
info: Microsoft.AspNetCore.SpaProxy.SpaProxyLaunchManager[0]
SPA development server running at 'https://localhost:44459'
info: Microsoft.AspNetCore.SpaProxy.SpaProxyMiddleware[0]
SPA proxy is ready. Redirecting to https://localhost:44459
運行開發腳本,埠 5273 或埠 44459 將重定向到實際的 Angular 應用程式。
但是,當我運行dotnet publish --configuration test并運行dotnet bin/test/net6.0/MyApp.Client.dllASP.NET 應用程式時,它會提供服務,但導航到埠只會回傳 404。我如何以與開發中完全相同的方式在給定埠上為 Angular 應用程式提供服務的方式實際運行應用程式?我是否需要運行 ASP.NET 應用程式,然后手動提供 Angular 應用程式的構建檔案?
我的csproj在下面
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<SpaRoot>ClientApp\</SpaRoot>
<SpaProxyServerUrl>https://localhost:44459</SpaProxyServerUrl>
<SpaProxyLaunchCommand>npm start</SpaProxyLaunchCommand>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.SpaProxy" Version="6.0.8" />
</ItemGroup>
<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>
<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="npm run build -- --configuration production" />
<!-- Include the newly-built files in the publish output -->
<ItemGroup>
<DistFiles Include="$(SpaRoot)dist\**; $(SpaRoot)dist-server\**" />
<ResolvedFileToPublish Include="@(DistFiles->'%(FullPath)')" Exclude="@(ResolvedFileToPublish)">
<RelativePath>wwwroot\%(RecursiveDir)%(FileName)%(Extension)</RelativePath>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
</ResolvedFileToPublish>
</ItemGroup>
</Target>
</Project>
uj5u.com熱心網友回復:
雖然 ASP.NET 管理 Angular 的開發,但沒有對已發布應用程式的管理。
為了部署應用程式,您必須運行dotnet publish并運行 ASP.NET 應用程式的實際 dll,使用dotnet <your dll e.g. bin/test/net6.0/publish/myapp.dll>. 然后通過 Nginx 或 VSCode 的 Live Server 之類的工具提供已發布的 Angular 檔案。
發布的檔案將wwwroot位于您的發布目錄中的檔案夾中,如上所示。或者您可以ng build在應用程式目錄中運行,它會將其放入名為 的檔案夾dist中,然后完全按照Angular 檔案中的指定部署它們。
因此,總結一下 ASP.NET 并沒有像在開發中那樣管理已部署的 Angular 應用程式。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/526345.html
標籤:C#网有角度的
