I have several customers using TFS 2015 and they are wanting to build and deploy the latest project types like Azure Functions. Having Visual Studio 2017 installed on the build server allows for many projects to build, however the .NET Core based csproj files are unable to build on TFS 2015 without some help. If you are getting an error using VSTS, ensure you are using the Hosted Visual Studio 2017 Agent queue.
On the TFS 2015 build, the first error I received was this one below.
Error MSB4041: The default XML namespace of the project must be the MSBuild XML namespace. If the project is authored in the MSBuild 2003 format
I focused on two options for solving this. One is to use Nuget and MSBuild. The other was using the dotnet CLI. I will discuss both options.
The desired outcome is to have a web deploy package. The way I know how to do this is through MSBuild arguments. To use MSBuild to build the solution, add a MSBuild build task instead of the Visual Studio Build task.
The key setting to change is to change MSBuild to use a specific version by selecting Specific Location under Advanced. Point the Path to the following location but do not include msbuild.exe.
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin
To create the deployment package, include the following parameters in the MSBuild arguments setting.
/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation=”$(build.artifactstagingdirectory)\\”
With these changes, I was able to get further in the build process. However the next error message I received was a Nuget restore error.
project.assets.json not found. Run a NuGet package restore to generate this file
To fix this using NuGet, I downloaded the latest version of Nuget.exe to a specific location on the build server. I pointed the Nuget restore task to this location and it fixed the issue. In this case, do include nuget.exe in the path.
To fix this using the dotnet CLI, add a Command line build task. Update the task to the following. Be sure to set the working folder to the folder that contains your solution.
With these two changes, the Azure Function CI build is succeeding.
Next we will verify we can deploy this to Azure.