VSTS fails to build my really really simple ASP.NET Core app - asp.net-core

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)

Related

"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

How to deploy an ASP.NET Core app with WebDeploy using TeamCity?

I'm having some trouble understanding how to publish an ASP.NET Core application to a server using Webdeploy on TeamCity.
I've installed the dotnet core teamcity plugin and have two build steps:
dotnet restore (as a command line step, the built in step timesout on nuget)
dotnet publish src/projectName/projectName.csproj
However I'm confused as to what to do for the third step, which is to publish the result of dotnet publish to our server.
Traditionally we'd use MSBuild and target a publish profile, however I'm unsure whether .NET core utilises MSBuild.
I've got a publish profile as part of my solution which works successfully within VS2017. I've had a look at the TeamCity blog which discusses setting up TeamCity to use .NET Core, and whilst it does mention WebDeploy, it just simply mentions it can be used alongside dotnet publish without really explaining how.
However I'm confused as to what to do for the third step, which is to publish the result of dotnet publish to our server.
Traditionally we'd use MSBuild and target a publish profile, however I'm unsure whether .NET core utilises MSBuild.
I've also found documentation on automated .NET Core deployment lacking. Generally for deploying to IIS you have two options.
You can still use MSBuild with /p:DeployOnBuild=true to deploy a .pubxml publish profile created in Visual Studio as with .NET framework sites. Run MSBuild after dotnet restore and instead of dotnet publish.
Or you can also use dotnet publish to publish to a folder, and msdeploy.exe to sync that folder to an IIS site, possibly on a remote machine. Typically:
msdeploy.exe -verb:sync -source:contentPath="<the folder published to by dotnet publish>" -dest:contentPath=<Your IIS Site>
I've using the next command to create web deploy package:
dotnet publish <Path_and_name_of_project>.csproj --configuration Release /p:PublishProfile=<profile_name>
and after this step, i've deploy package to iis via webdeploy command

.NET Core - When to use "dotnet new sln"

I'm a bit confused - the majority of .NET Core tutorials I have been reading have not mentioned "dotnet new sln" - they always just create the projects separately without any solution file to link them together.
Is "dotnet new sln" a new command?
When should I use this? What benefits do I gain from creating a .sln file instead of just having project files? Is it mainly for opening in Visual Studio? I use Visual Studio Code for Mac, so it may not be applicable.
I have googled "dotnet new sln" and the results are very minimal.
Is "dotnet new sln" a new command?
Yes. In version 1.0.1 of the dotnet command line interface, there is a dotnet new sln command. The command came with the change from project.json to csproj. If we run dotnet new --help, we will see "Solution File" as one of the templates.
> dotnet new --help
Templates Short Name Language Tags
----------------------------------------------------------------------
Console Application console [C#], F# Common/Console
Class library classlib [C#], F# Common/Library
Unit Test Project mstest [C#], F# Test/MSTest
xUnit Test Project xunit [C#], F# Test/xUnit
ASP.NET Core Empty web [C#] Web/Empty
ASP.NET Core Web App mvc [C#], F# Web/MVC
ASP.NET Core Web API webapi [C#] Web/WebAPI
Solution File sln Solution
when should I use this?
Two times to use a solution file are:
when we want to use Visual Studio, and/or
when we want to manage several projects as a single unit.
What benefits do I gain from creating a .sln file instead of just having project files? Is it mainly for opening in Visual Studio? I use Visual Studio Code for Mac, so it may not be applicable.
One of the benefits that do not require Visual Studio is the management of multiple projects as a single unit.
For instance, on a Mac with Visual Studio Code, we can use the dotnet CLI to create a new solution, create a few projects, add those projects to the solution, restore the solution, and build the solution.
dotnet new sln --name FooBar
dotnet new console --name Foo --output Foo
dotnet new console --name Bar --output Bar
dotnet sln add .\Foo\Foo.csproj
dotnet sln add .\Bar\Bar.csproj
dotnet restore
dotnet build FooBar.sln
The last command, which calls dotnet build, has the benefit of building all the projects that are in the solution. Without a solution, we would need to call dotnet build on each project.
There are no doubt other benefits which do not require the use of Visual Studio. I leave those to you to discover.

Building .NET Core 1.0 RC2 app on the build server

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.