Welcome to today’s post.
I will we discussing how to troubleshoot issues that occur when we configure and execute build, test and deployment pipelines (into an existing Azure app service) for .NET Core web applications within a TeamCity CI build configuration.
In one of my previous posts, I discussed how to configure a basic build configuration using TeamCity CI to check out the source from GitHub repository, then build and run a set of unit tests.
In a follow up post, I discussed how to configure a TeamCity build configuration to deploy a .NET Core application into an Azure app service.
In this post I will discuss how to identify and resolve some common errors that will appear during a build, test, release pipeline within TeamCity. One of the most common errors we may experience is the one below from the build history:
It is clearly not helpful, so we inspect the build log to determine the cause:
[13:49:48][test] MSBUILD : error MSB1003: Specify a project or solution file. The current working directory does not contain a project or solution file.
This error is most likely due to the working directory referenced in the build step referencing an source folder that does not have a project or solution file.
The working folder parameter is shown in the image below:
The common error is shown below:
On inspecting the build log we find more details:
[13:58:10][test] UnitTestMain.cs(4,7): error CS0246: The type or namespace name 'BookLoan' could not be found (are you missing a using directive or an assembly reference?)
The most likely cause for this error is due to one of the steps before the current build step returning an error. With missing namespace errors, it is possibly due to one of the following going into error:
- during a source checkout from the VCS
- building of the project source
- restoration of NuGet packages
To rectify this, check one of the following:
- network connectivity
- VCS credentials
- application compilation
- build steps are all enabled
The next type of error relates to deployment build tasks. User authentication or authorization error are quite common when fine tuning MSBuild deployment parameters. The error is show below in the build history:
The build log shows:
To determine root the cause we open the MSBuild deployment task and inspect the command line parameters.
Check the following:
- Build parameters for destination site credentials %deployusername% and %deploypwd%
- Check the destination (from the publish profile file) site is correct
- Check the application can deploy from the publish wizard without error
- Check the deployment credentials are correctly configured for the application within Azure App Services
- Incorrectly prefixing the user name with a “$” as it is in the publish profile. The parameter should not be prefixed with a $.
The next type of error relates to authorization. The build history does not give much detail:
View the build log for further details:
Again, this has a similar remedy for the above authentication error: check the user deployment credentials in the build parameters match those in Azure app deployment center.
The next error is more cryptic to understand or troubleshoot. The error in the build history and detail shows:
Even though the publish task may work within Visual Studio, with MSBuild the target is treated like a new application!
Check the following:
- Site destination within the publisher profile.
- Deployment service URL is correct.
- Do not use MSBuild parameters that are already in the publish profile file.
Note: with the last point, any parameters that are duplicated in the MSBuild command outside of the /p:PublishProfile=… command will be regarded as replacing the corresponding setting in Azure, and deployments from MSDeploy only allow existing deployments without changing site settings.
For example, using the following build parameters in this way may lead to the above error:
/p:PublishProfile="Properties\PublishProfiles\BookLoanWebApp - Web Deploy.pubxml" /p:MsDeployServiceUrl=someapp.scm.azurewebsites.net:443 /p:DeployIisAppPath=http://someapp.azurewebsites.net /p:DeployOnBuild=True /p:ProfileTransformWebConfigEnabled=False /p:userName=%deployusername% /p:password=%deploypwd% /p:EnableMSDeployAppOffline=True /p:verb=sync /p:dest=auto
The following parameters below would cause the deployment to fail as the app name someapp and app path would be replacing the app and path that is existing in your Azure app service.
That’s all for today’s post!
I hope this post is useful and informative.