How to deploy an ASP.NET Core app with WebDeploy using TeamCity? - asp.net-core

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

Related

dotnet publish for ASP.NET Core project doesn't publish on FileSystem

When using the command
dotnet build /p:DeployOnBuild=true /p:PublishProfile=CustomProfile
my ASP.NET Core project builds and gets published using the FileSystem publishing method.
When I use the
dotnet publish /p:PublishProfile=CustomProfile
command (which should do the publish part only) the build part gets done but no publish actions are done.
Is this a limitation from dotnet?
Is there a workaround?
My system:
dotnet --version
3.1.201
VS2019 16.5.3

Publish console application via command line using specific publish profile

I try to build and publish my .NET Core applications on the command line using predefined publish profiles.
For a ASP.NET Core application this (taken from here) works:
dotnet build -c Release /p:DeployOnBuild=true /p:PublishProfile=ReleaseFolder
But for a console application (where the publish profile is called FolderProfile, the following does not work:
dotnet build -c Release /p:DeployOnBuild=true /p:PublishProfile=FolderProfile
It builds the project but does not publish it.
So how can I publish a console application using a predefined publish profile?
Publish profile support is part of the web-SDK which is used by the web targets. ASP.NET Core applications typically use the Microsoft.NET.Sdk.Web wheres console applications use the Microsoft.NET.Sdk project.
Since console applications therefor don't include the web SDK's publishing support, you can only use the Publish target which generates deployable outputs. It is wrapped by the dotnet cli's dotnet publish command and can alternatively be used as msbuild /t:Publish. This publish command has no support for publish profiles since it is only a filesystem based operation.
You can now add the Microsoft.NET.Sdk.Publish sdk to your project file. That will enable you to use dotnet publish for your project.
<Project Sdk="Microsoft.NET.Sdk;Microsoft.NET.Sdk.Publish">

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)

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.

ASP.NET 5: Where are my output DLLs when publishing?

Where are my output DLLs when publishing an ASP.NET 5 web application?
When running the MSBuild's FileSystemPublish, the publish directory looks something like this:
approot folder: packages, runtime and source code
wwwroot folder: web.config and AspNet.Loader.dll
web
web.cmd
MSBuild.exe "C:/MyApplication/MyProj.xproj" /t:Build,FileSystemPublish /p:PublishConfiguration=Release /p:PublishOutputPathNoTrailingSlash="C:/a/MyApplication"
From the logging output I can see that dnu publish is called:
dnu publish "C:/MyApplication" --out "C:/a/MyApplication" --configuration Release --runtime dnx-clr-win-x86.1.0.0-beta6 --quiet
If I look inside web.cmd I can see that DNX is indeed running the application from source code:
#"%~dp0approot\runtimes\dnx-clr-win-x86.1.0.0-beta6\bin\dnx.exe" --appbase "%~dp0approot\src\MyApplication" Microsoft.Framework.ApplicationHost web %*
I am able to point IIS to the wwwroot directory with success.
How does IIS know to call on web.cmd? Is this the correct approach to serving up an ASP.NET 5 application in a production environment?
IIS doesn't call web.cmd. IIS knows how to load AspNet.Loader from the wwwroot folder.
In a production environment you probably don't want to compile from sources because the startup is pretty slow. You should publish precompiled binaries. You do that by passing --no-source to dnu publish:
dnu publish "C:/MyApplication" --out "C:/a/MyApplication" --configuration Release --runtime dnx-clr-win-x86.1.0.0-beta6 --no-source
The question is obsolete
According to the latest community standup (see Announcement), the HELIOS integration between IIS and asp.net 5 was stopped. Ongoing the only server provided by MS is kestrel. IIS will natively not recognize DNX projects.
You have to start and integrate kestrel into IIS by reverse proxying it using the HttpPlatformHandler (IIS8+).