TeamCity WindowsAzure.targets causing errors in deployment - azure

We are currently trying to setup an Angular 2 project that also contains a Cloud Service project in its solution. We have set up numerous Angular 1 projects containing Cloud Service projects and have had no errors. When trying to run the MSBuild step for the Angular 2 project, we get the following error on the TeamCity build server:
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Windows Azure Tools\2.7\Microsoft.WindowsAzure.targets(2787, 5): error MSB3021: Unable to copy file "C:\TeamCityBuildAgent\temp\buildTmp\.NETFramework,Version=v4.6.1.AssemblyAttributes.cs" to "C:\SourceControlFolder\Apps\MyApp\MyApp.CloudDeployment\obj\Debug\Website\C:\TeamCityBuildAgent\temp\buildTmp\.NETFramework,Version=v4.6.1.AssemblyAttributes.cs". The given path's format is not supported.
The main problem seems to be the build attempting to throw the full C:\TeamCityBuildAgent.. path into the obj\Debug\Website folder.
My current MSBuild parameters are:
/p:Configuration="Dev"
/p:platform="Any CPU"
/p:OctoPackEnforceAddingFiles=true
/p:OctoPackProjectName=MyApp_Dev
I've tried the following solutions:
Making sure the latest Visual Studio Update is installed (for MSBuild)
Running the install tool to repair Azure Tools 2.7 on the build server.
Changing the debug configuration in the build.
Ensuring TypeScript 1.7.6 is installed on the build server (even though it's an Azure.targets issue) [https://github.com/Microsoft/TypeScript/issues/6215]
Updated the project to Azure Tools 2.9. The same error remains except it's failing on the 2.9 folder instead now.
Curious if anyone else has experienced this error and knows a fix. I'll keep this post updated as I try other solutions.
Update
It appears that what is causing this issue is this line within the .csproj file:
<FilesToIncludeForPublish>AllFilesInProjectFolder</FilesToIncludeForPublish>
This is specified for our build configurations to copy all files generated by the ng build to the output directory of the publish. What I don't understand at the moment is how this works on all of the devs' local machines but does not work on our build server. Will keep this posted as I find more info or any kind of workaround.

This ended up being the fix:
Instead of targeting the .sln in MSBuild, we specifically targeted the .csproj file. This fixed the build errors and allowed us to keep the FilesToIncludeForPublish tag inside.

Related

error MSB4086: A numeric comparison was attempted on "$(MSBuildVersion)" that evaluates to "" instead of a number

Trying to deploy the project with Azure Kudu (reading from a BitBucket repo) I get the following error in Deployment Center within Azure Portal...
This error happened with all the latest versions of Microsoft.Net.Compilers NuGet package. The only version that worked was 3.0.0 from 5 months ago.
Anyone knows what's the cause of this? Is Azure Kudu not yet updated?
Command: "D:\home\site\deployments\tools\deploy.cmd"
Handling .NET Web Application deployment.
MSBuild auto-detection: using msbuild version '14.0.23107.0 built by: D14REL' from 'D:\Program Files (x86)\MSBuild\14.0\Bin'.
Restoring NuGet package Microsoft.Net.Compilers.3.1.1.
GET https://api.nuget.org/v3-flatcontainer/microsoft.net.compilers/3.1.1/microsoft.net.compilers.3.1.1.nupkg
OK https://api.nuget.org/v3-flatcontainer/microsoft.net.compilers/3.1.1/microsoft.net.compilers.3.1.1.nupkg 937ms
Installing Microsoft.Net.Compilers 3.1.1.
Adding package 'Microsoft.Net.Compilers.3.1.1' to folder 'D:\home\site\repository\packages'
Added package 'Microsoft.Net.Compilers.3.1.1' to folder 'D:\home\site\repository\packages'
NuGet Config files used:
D:\local\UserProfile\AppData\Roaming\NuGet\NuGet.Config
Feeds used:
D:\home\.nuget\
https://api.nuget.org/v3/index.json
Installed:
1 package(s) to packages.config projects
D:\home\site\repository\packages\Microsoft.Net.Compilers.3.1.1\tools\Microsoft.Managed.Core.targets(63,60): error MSB4086: A numeric comparison was attempted on "$(MSBuildVersion)" that evaluates to "" instead of a number, in condition "$(MSBuildVersion) >= 16.1.0". [D:\home\site\repository\MyCompany\MyCompany.csproj]
Failed exitCode=1, command="D:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" "D:\home\site\repository\MyCompany\MyCompany.csproj" /nologo /verbosity:m /t:Build /t:pipelinePreDeployCopyAllFilesToOneFolder /p:_PackageTempDir="D:\local\Temp\8d727f56aa60788";AutoParameterizationWebConfigConnectionStrings=false;Configuration=Release;UseSharedCompilation=false /p:SolutionDir="D:\home\site\repository\.\\"
An error has occurred during web site deployment.
\r\nD:\Program Files (x86)\SiteExtensions\Kudu\84.10807.4030\bin\Scripts\starter.cmd "D:\home\site\deployments\tools\deploy.cmd"
### EDIT ###
I also opened an issue # Kudu GitHub repo.
I’ve had a similar issue with a kudu deployment and typescript versions. The basic issue seem to be that kudu is on its way out in favour of Azure DevOps so some dependencies of msbuild are becoming out of date. These are three options that might help you resolve the issue:
Switch to Azure DevOps - you’ll have access to various build agents and much more control over what they are capable of, but generally they’ll just be more up to date
Amend your build script - this is the script that kudu uses and you can customise it and then put it in source control, see this kudu doc for more info. Looks like you’re targeting msbuild 14 but I’m pretty sure 15 should be available and you can point your build script at this and/or make other tweaks
Process some of your build offline, ie before committing - this was my temporary solution with typescript, I was able to transpile to JavaScript and commit the js meaning I could disable typescript processing for kudu
It may also help to dig around in the targets file referenced in your log and trace back where the problem starts through the various msbuild conditions in that file. You can see all this by exploring via a command prompt in kudu.

"Illegal characters in path" error in compiling and packaging azure web app with web job

I have an web application "WebApplication2" (Azure API) with a web job "WebJob1". I want to package the application along with the web job to a zip file in order to deploy the package to the cloud. When I do it via visual studio (Publish -> web deploy package) it works like a charm. But when I'm trying to do it via MSBuild (for automation purposes) I'm getting this error:
The command:
C:\Program Files (x86)\MSBuild\14.0\Bin>MSBuild.exe "C:\Users\levs\Documents\Visual Studio 2015\Projects\WebApplication2\WebApplication2\WebApplication2.csproj" /p:OutputPath="C:\Users\levs\Documents\webPublish\MSBuildOutputPath" /p:DeployOnBuild=true /p:PackageLocation=C:\Users\levs\Documents\webPublish\test.zip /verbosity:m
The output:
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web\Microsoft.Web.Publishing.targets(2606,5): error : Copying file C:\Users\levs\Documents\webPublish\MSBuildOutputPath**\*.* to obj\Debug\Package \PackageTmp\app_data\jobs\continuous\WebJob1\*.* failed. Illegal characters in path. [C:\Users\levs\Documents\Visual Studio 2015\Projects\WebApplication2\WebApplication2\WebApplication2.csproj]
Do you have any idea what I'm doing wrong?
BTW, the compilation of each project (the application and the webjob) separately with MSBuild works.
MSBuild version : Microsoft (R) Build Engine version 14.0.25420.1
Not sure what you were using for scripting the automation but I've had similar trouble using MSBuild in Cake with my web job. Hopefully this might help anyone else who stumbles upon the same issue.
My original paths during the copy were this:
Copying C:\Test\Portal.WebApp\build\Package**\*.* to obj\Release\Package\PackageTmp\app_data\jobs\triggered\PortalWebJob\*.*
The issue I believe was with this part.
Package**\*.*
To fix this I added slash to end of my OutputPath.
settings.WithProperty("OutputPath", MakeAbsolute(packageDir).ToString() + "/");
This seemed to fix things for me, I know you may not being using Cake scripts but hopefully this might steer you in the right direction.
I fixed this by finding the MSBuildOutputPath value that was failing, copying it, adding a trailing slash, and then specifying that new string as the OutputPath argument.
So if the output that is giving me that error was "C:/myDesiredOutputPath/bin" I needed to specify MSBuild should use "C:/myDesiredOutputPath/bin/" with a trailing slash.
msbuild /p:OutputPath=C:/myDesiredOutputPath/bin/
This answer may be helpful.

GitHub project deployment failed on azure

I want to deploy my .Net project from GitHub repository to the azure server.
In Deployment options I am getting Building failed error.
Here are screen shots of my Deployment details and Logs
1- Deployment Details:
2- Activity Log:
According to your description and logs, I found you have error in MSbuild step.
The error shows some files not found in your project. I suggest you could exclude the related files in the csproj file or make sure the related files is in your project.
Besides, I suggest you could firstly clone the project to your local and test it , make sure the project could build well without any error then publish to the GitHub and deploy to the azure.
Update:
I also write a test demo on my computer and I reproduce your error.
Error image:
I think in your project you have inclued the bin and obj folder into your project and then you push the project to the github.
Like below:
After you push the project to the github, the csporj file will include all the bin and obj references.
Like below:
This is the reason about your MSBuild fail.
So I suggest you uninclude all the bin and obj folder in the local and push to the github again. Then it will work well.
Azure looks in your site/repository/packages folder for all the packages your app uses. By looking through it you will find that visual studio doesn't deploy all of the files from your local packages folder to the azure one. MSBuild needs these files when you push to git and trigger a build. Ftp into your azure site and look for the packages folder. Upload every missing file (dll) from your local folder to the azure one. This worked for me and now I can trigger a build and deployment from bitbucket to azure app service upon a push.
Additionally, if you have other projects in your VS solution and you are using VS to build those projects and then put the dll into your main projects bin folder, that will cause a missing file error also. I create a folder in my packages folder and link the dll to my main folder from there. That way when you perform the fix above, the file needed by your main project is in the packages folder also.
I hope this helps!

Nodejs TFS Build Definition

Can anyone let me know how the build definition for a node.js application should look like? Also how to mention the mocha tests in the Automated tests?
First time when I tried to queue a build, I got an error saying:
Microsoft.NodejsTools.targets not found.
So I went and copied the NodejsTools folder with the .target and dll file in my build server. And I didn't see the error.
Now I get the below error:
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\WebApplications\Microsoft.WebApplication.targets (132): Could not copy the file "obj\Debug\OstNodeJs.exe" because it was not found.
You need the node.js framework and the Visual Studio node.js Tools on you build server, too. You just copied the necessarily files and this may result in other problems.
For the executable copy problem you can try to add <Disable_CopyWebApplication>True</Disable_CopyWebApplication> in the project file. See here: Build on TFS wants to copy a executable from Node.js test project

Adding cache worker role causes build error

I have an Azure cloud service project to which I am adding a cache worker role. While local build goes through fine, I get the following error on my server builds :
CloudServices38 : The entrypoint dll is not defined for worker role <cachename>
What is wrong? How do I fix this?
Make sure all the Azure DLLs are marked Copy Local = True in the properties window. Also, package your projects, then unzip them. Once you build the package, you will have a file YourProject.cspkg. Change the extension from .cspkg to .zip and extract the files. In these files you should see a file with the extension .cssx YourProject_.cssx. Change the extension from .cssx to .zip and extract again. You project that is deployed will be in the folder YourProject\sitesroot\0 - verufy all the files you are expecting (i.e. content and everything that is in the bin directory on your local build.
You need to run a Build and a Publish separately. I ran into the same problem on my project and this fixed it.
1) Visual Studio Build (or MSBuild) action with arguments /t:Build (clean here)
2) Visual Studio Build (or MSBuild) action with arguments /t:Publish (do not clean here)
Note: I had to run these actions separately (not /Build;Publish) otherwise I got an error about the cloud service entry point.
Pieced this together from this question and from here and here.

Resources