Azure中deploy.cmd缺失,自定义部署实现MS单元测试自动化遇阻求助
Troubleshooting Missing
deploy.cmd & Adding MS Unit Tests to Custom Deployment Scripts Hey there, let's walk through fixing your deployment script issues and getting those MS Unit Tests running automatically.
First: Fixing the Missing deploy.cmd File
If you can't find deploy.cmd in Site\deployments\tools, here's how to get it:
- Generate it locally with Azure CLI: Open your terminal and run this command (replace placeholders with your app details):
This will create aaz webapp deployment script --name <your-app-service-name> --resource-group <your-resource-group> --script-type cmddeploy.cmdfile and a.deploymentconfig file right on your local machine—you can edit these before uploading. - Check Kudu Console: Log into your app's Kudu dashboard, navigate to
site\deployments. If thetoolsfolder doesn't exist, trigger a basic deployment first (like pushing a small change to your repo) to generate default deployment artifacts, or upload your manually createddeploy.cmddirectly.
Fixing Deployment Script Download Failures
If the Portal's "Download deployment scripts" tool isn't working:
- Try Kudu directly: In Kudu, go to
Tools > Download deployment script—this often bypasses Portal caching issues. If that still fails, use the Azure CLI method above to generate the script locally instead. - Clear Portal cache: Refresh the Azure Portal page, or open it in an incognito window to rule out cached errors.
Adding MS Unit Tests to Your Custom Script
Once you have deploy.cmd, edit it to add test execution steps. Here's a typical example:
- Restore dependencies first (add this before the deployment step):
:: Restore NuGet packages for test project cd "%DEPLOYMENT_SOURCE%\YourTestProjectDirectory" nuget restore YourTestProject.csproj - Run the tests (place this right before the deployment starts, or after build completes):
Note: Adjust the Visual Studio version path and test DLL name to match your setup.:: Execute MS Unit Tests cd "%DEPLOYMENT_SOURCE%\YourTestProjectDirectory\bin\Release" "%ProgramFiles(x86)%\Microsoft Visual Studio\2022\BuildTools\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe" YourTestProject.dll /Logger:trx
Deploying Your Custom Script
- Upload your edited
deploy.cmdand the.deploymentfile (make sure it has a[config]section pointing todeploy.cmd) to the root of your deployment source (Git repo, blob storage, etc.). Azure will automatically use this custom script for future deployments.
内容的提问来源于stack exchange,提问作者Ragu
相关产品推荐
相关产品推荐

