Building .NET Core 1.0 RC2 app on the build server - msbuild

I've updated my app from DNX, ASP.NET 5 RC1 to ASP.NET Core 1.0 RC2.
Locally it builds and runs fine.
On the build server, I don't have Visual Studio installed, and the build fails with:
error MSB4019: The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Props" was not found. Confirm that the path in the declaration is correct, and that the file exists on disk.
I did install the: .NET Core SDK for Windows.
Trying to install the VS 2015 tooling preview fails with:
What would be the correct setup to build .NET Core 1.0 RC2 app on the build server without having to install Visual Studio 2015?
Note: The build box (TeamCity 9) builds/runs tests fine for .NET 4.5 and DNX.

https://learn.microsoft.com/en-us/dotnet/articles/core/windows-prerequisites#issues
Issues
You may be blocked from installing the .NET Core Tooling Preview 2 for Visual Studio 2015 installer due to a temporary bug. To workaround it, run the installer from the commandline with the SKIP_VSU_CHECK=1 argument, as you see in the example below.
DotNetCore.1.0.0-VS2015Tools.Preview2.exe SKIP_VSU_CHECK=1

I'm able to build the solution now. Still can't publish though.
I just copied all the new MSBuild stuff to the build server. I copied:
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\
From my local computer to the build server. That includes the new DotNet sub-folder, which contains:
Microsoft.DotNet.Common.targets
Microsoft.DotNet.Extensions.targets
Microsoft.DotNet.props
Microsoft.DotNet.Publishing.targets
Microsoft.DotNet.targets
Microsoft.DotNet.Tasks.dll
Microsoft.VisualStudio.ProjectSystem.DotNet.Runtime.dll
Newtonsoft.Json.dll
I can build the Solution (without the publish arguments) it fails when I try:
MSBuild.exe Solution.sln /p:DeployOnBuild=true /p:publishprofile=local

You can build and test you project via the command line - so there is no need to have Visual Studio installed. By using build steps of type "Command Line" you can run: dotnet restore, dotnet build, dotnet test
Here you can find some description how to run that as a build on TFS. It is written for the hosted TFS but works on-premise as well (and is not only meant for azure as the name of the document might imply):
https://www.visualstudio.com/en-us/docs/build/apps/aspnet/aspnetcore-to-azure
For the pubsishing I have used msdeploy with RC1 but have not yet migrated my deployment build. I might document it here when this is done within the next days.

So without Visual Studio or Web Deploy, my TeamCity build is comprised of 4 builds steps:
dotnet restore
dotnet build
dotnet test
dotnet publish -c Release
I run dotnet test on all projects with a basic for loop.

Related

Appveyor CI fails to build a .net core 2.1 solution with a database project

Our .net core 2.1 solution compiles fine on our local development machines with .net core sdk 2.1.301. Appveyor used to compile the solution in its CI pipeline when there was no database projects defined. Once such a project added, Appveyor started failing in building the solution with the error message below. Any clues how to address this issue?
C:\projects\comingsoon\ComsingSoonDatabase\ComsingSoonDatabase.sqlproj(57,3):
error MSB4019: The imported project "C:\Program
Files\dotnet\sdk\2.1.300\Microsoft\VisualStudio\v11.0\SSDT\Microsoft.Data.Tools.Schema.SqlTasks.targets"
was not found. Confirm that the path in the declaration is
correct, and that the file exists on disk.
The database project can only be built using the full framework MSBuild tools included in visual studio.
Depending on how you set up appveyor, you need to change your definition to use msbuild.exe instead of dotnet commands.

"dotnet publish" (.net core) build step not working in visual studio team services with multiple projects

We have a VS 2017 solution with one WCF-service project and one .net-core web-application targeting .net framework 4.5.2 and .net core 1.0 (1.0.0-preview2-003131).
By some reason I cannot get the website published through "dotnet publish"-command in visual studio team services.
The problem shows up in build step "dotnet publish", project is specified to match only the web-projects solution-file (**/InventoryIndexWeb.csproj) since I only want the web to be published in this build.
Gives the following errors:
MSBUILD : error MSB1008: Only one project can be specified.
Dotnet command failed with non-zero exit code on the following projects : d:\a\3\s\WebSites\InventoryIndex\Staging\InventoryIndexWeb\InventoryIndexWeb.csproj
See screenshot for details:
Any suggestions how to solve this or workarounds? The plan is to push this to Octopus deploy as well when we get the publish step working.
You cannot pass multiple projects / arguments to dotnet publish.
In your case you seem to have passed the artifacts folder as second argument. To do this, add -o before that directory:
dotnet publish your.csproj -o $(Build.ArtifactStagingDirectory)
Changing to pass -o as parameter instead of only $(Build.ArtifactStagingDirectory) did the trick as Martin stated above, and final configuration as below.

.NET Standard and TFS 2015 -> Build failures

My infrastructure now has TFS 2015, but we started a new project in .NET Standard. Our build server now has VS2017, and the project builds when loaded within VS2017 in that server.
When we set a new build definition to run the build through the build agent, then it fails. Seems even that System is not found:
Error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?)
Is there any simple thing to do to make it work, ir we will have to migrate to the new build steps to make it work? Some workaround?
I find a workaround for that. Simply I gave up of using the TFS 2015 build steps MSBUILD and Visual Studio Build, and now I am using the Command Line step. Calling the commands from there:
dotnet restore
dotnet build
That does the trick.
This is because we need to do our restore a different way using the .net core restore. You could fix this by adding the .NET Core (PREVIEW) task to the build definition or just use command line task. With command line task could running dotnet restore, dotnet build, dotnet publish, and dotnet test.
More details please take a look at this blog: Setting up .net core continuous integration build with VSTS/TFS
For command line solution please refer vsts-agent Build Definition for .NET Core (with Test Results) Also take a look at this similar question: Visual studio team services build .net core 1.1

VSTS fails to build my really really simple ASP.NET Core app

The following is so so simply and yet it fails. What's wrong?
I create a new ASP.NET Core Web Application (.NET Framework 4.6.2) in Visual Studio 2017.
I make no changes to the default template and I push it to VSTS.
I create a new build definition in VSTS with the following two steps:
NuGet Restore
Visual Studio Build
I update the NuGet step to use version 4.0.0
I update the definition to use the Hosted VS2017 agent.
I leave the Build step using VS2017 with the default MSBuild arguments:
/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)\\".
In previous versions this would create me a web deployment package which is exactly what I want.
I queue a new build.
The NuGet step succeeds.
The build step runs until it logs...
_TransformWebConfig:
...and then...
No web.config found. Creating 'C:\a\1\s\src\WebApp\obj\Release\net462\win7-x86\PubTmp\Out\web.config'
...and...
Microsoft.NET.Sdk.Publish.MSDeployPackage.targets(124,7): Error MSB4184: The expression "[System.IO.Path]::GetDirectoryName('')" cannot be evaluated. The path is not of a legal form.
This issue has been fixed: https://github.com/aspnet/websdk/issues/106
Sample commandline and syntax to use in VSTS (ASPNET Core templates should already have this in the template): https://github.com/vijayrkn/ASPNetPublishSamples/blob/bff9f78d796668dc07d5e28a8b93531caade839c/Publish.cmd#L102-L127
You can use ASP.NET Core (Preview) build template, it publishes the .Net Core app through dotnet tool.
Create a new build definition
Select ASP.NET Core (Preview) build template
I think the follwing article has the answer.
https://www.visualstudio.com/en-us/docs/build/apps/aspnet/aspnetcore-to-azure.
In summary, don't use Visual Studio to do the build, use the CLI instead, i.e.
dotnet.exe publish -c $(BuildConfiguration) -o $(Build.ArtifactStagingDirectory)

Using NuGet 4.0 with VSTS?

Upgraded our ASP.Net Core project (using full .Net Framework) from .json project to .csproj format, using VisualStudio 2017, and the project builds and runs just fine locally.
From what I understand NuGet 4 is bundled with VisualStudio 2017.
Trying to build this using VisualStudioTeamServices fails on the "Nuget installer" task, as we can only select version 3.5 of NuGet for this task. (And yes, Visual Studio 2017 is installed on the build server, and the agent has been updated to have the capabilities updated)
There is an argument to enter a custom path for nuget in this task, could this be used? Or do we have to wait for an updated version of the Nuget installer build task?
If anybody else has the same problem, I figured out that we no longer need the "Nuget installer" step. Simply add "/t:restore" as an argument to MsBuild.