我在服务器文件夹中创建了一个Web Api Asp.Net核心项目,在客户端文件夹中创建了一个Angular-Cli项目。
我用IIS Express启动WebAPI,用
ng serve --proxy-config proxy.config.json*.
在我的Angular App的environment / environment.ts中,为了能够使用environment.apiUrl获取ApiUrl (代理不适用于SignalR使用的websocket),我添加了一个新参数:
apiUrl: "http://localhost:49402/"
文件结构:
我的项目也可以在git上使用:https : //github.com/ranouf/AspNetCore-SignalR/
我创建了一个新的WebApp,
我配置了部署选项,每次修改master时,都会部署适合我的WebApi的Web App。
如何在Azure的Web应用程序中部署我的Angular应用程序?
我添加了一个后构建命令,该命令仅在发布模式下才能在wwwroot文件夹中构建我的角度应用程序。此解决方案在本地有效,但在Azure上无效:
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<PostBuildEvent>
cd "$(MSBuildProjectDirectory)/../../client"
npm install
npm run build
</PostBuildEvent>
</PropertyGroup>
在startup.cs中,我添加了
app.UseDefaultFiles();
app.UseStaticFiles();
我必须在本地将我的2个项目分开,不能使用webpack microsoft angular模板。
谢谢你的帮助。塞德里克
所以我还在努力。
调试和了解Azure Portal上发生的事情真的很难。登录Deployment不会提供构建输出。
我的新的预构建命令是:
echo "$(ProjectDir)..\..\client"
cd $(ProjectDir)..\..\client
echo "npm install"
npm install
echo "ng build"
ng build --env=prod --prod --output-path=$(ProjectDir)
But still, nothing is copied in the server folder ...
Please, can you share your thinking? How can I deploy my angular App using Deployment Option in Azure portal?
So, I saw no solution online, and no one answer here too, so what I want to do first seems to not be possible.
I try something else, the kudu deployment script. You need to add two file:
.deployment with this lines inside:
[config]
command = deploy.cmd
deploy.cmd:
@if "%SCM_TRACE_LEVEL%" NEQ "4" @echo off
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Setup
:: -----
setlocal enabledelayedexpansion
IF NOT DEFINED DEPLOYMENT_SOURCE (
SET DEPLOYMENT_SOURCE=%ARTIFACTS%\repository
)
IF NOT DEFINED DEPLOYMENT_TARGET (
SET DEPLOYMENT_TARGET=%ARTIFACTS%\wwwroot
)
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Deployment
:: ----------
echo Source: %DEPLOYMENT_SOURCE%...
echo Deployment: in %DEPLOYMENT_TARGET%...
echo Server off
touch %DEPLOYMENT_TARGET%\App_Offline.htm
pushd "%DEPLOYMENT_SOURCE%\src\client"
echo npm install --production
call :ExecuteCmd npm install --production
IF !ERRORLEVEL! NEQ 0 goto error
echo Deploy client
call :ExecuteCmd npm run build-azure
IF !ERRORLEVEL! NEQ 0 goto error
popd
echo Deploy API
call :ExecuteCmd dotnet publish src\server\AspNetCore-SignalR.Api\ -o %DEPLOYMENT_TARGET%
IF !ERRORLEVEL! NEQ 0 goto error
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: End
:: ---
IF !ERRORLEVEL! NEQ 0 goto error
goto end
:: Execute command routine that will echo out when error
:ExecuteCmd
setlocal
set _CMD_=%*
call %_CMD_%
if "%ERRORLEVEL%" NEQ "0" echo Failed exitCode=%ERRORLEVEL%, command=%_CMD_%
exit /b %ERRORLEVEL%
:error
endlocal
echo An error has occurred during web site deployment.
call :exitSetErrorLevel
call :exitFromFunction 2>nul
:exitSetErrorLevel
exit /b 1
:exitFromFunction
()
:end
endlocal
echo Finished successfully.
There is 2 good points:
There is 1 BIG problem:
How to make understand to the web.config that I want both work Angular App and Swagger?
I found the solution! It was hard, I tried many things even the Kudu Deploy script:
(for those who could be interested to see how to do that).
But finally, I choose the (maybe) easiest solution, the PreBuildEvent command.
In my csproj:
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<PreBuildEvent>
cd "$(MSBuildProjectDirectory)/../../client"
npm install
</PreBuildEvent>
<PostBuildEvent>
cd "$(MSBuildProjectDirectory)/../../client"
npm run build-azure
</PostBuildEvent>
</PropertyGroup>
In Package.json:
"build": "ng build --env=prod --prod --output-path=../server/AspNetCore-SignalR.Api/wwwroot/",
"build-azure": "ng build --env=prod --prod --output-path=D:/home/site/wwwroot/wwwroot/",
The main things to know is when you want to deploy an Angular App, you need to do it in wwwroot folder. In Azure, the .Net app is deployed in D:/home/site/wwwroot/. My mistake was to think that I have to deploy my angular app there too. The good thing to do is to deploy it in D:/home/site/wwwroot/wwwroot.
我希望我的工作也会对人们有所帮助。如果您有任何改进流程和增强安全性的建议,请告诉我们。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句