Deploying dotnet core projects in TFS 2017 - c#

Does anyone know how to build a definition for a dotnet core project for IIS using using TFS 2017?
Problem I am having when I build and deploy currently it only produces a container type build which only includes 5 files and no dependencies.
Anyone help?

Sorted. I had to do a msbuild and publish using the msbuild task.

You need to use dotnet command in Command line task to restore the NuGet package and build/publish the output to a folder.
publish -c $(BuildConfiguration) -o $(Build.ArtifactStagingDirectory)
After you've run the build, you could create a release definition to deploy your app to an IIS server.
More detail steps please refer below tutorial:
Build your ASP.NET Core app
Deploy your Web Deploy package to IIS servers
Setting up .net core continuous integration build with VSTS/TFS

Related

Trying to install MonoGame for mac and VS Code

I'm trying to install MonoGame for mac and VS code. I followed the instructions at https://docs.monogame.net/articles/getting_started/1_setting_up_your_development_environment_macos.html, but I am stuck at one place. I have the monogame editor .mpack file, but can't upload it to VS code for some reason. I did extensive research but can't find any answers. What should I do?
The "normal" Mac install instructions and files are only for use with Visual Studio.
Install using CLI
Please note these instructions are designed for Intel Macs(x64), but should work on Apple Silicon devices(ARM) with .Net6.
You can roughly follow the Linux install instructions.
Install Dot Net Core 3.1 for the Mac. or .Net6
Install VS Code.
You may need to reference this question on Terminal paths for code. Something similar may need to be done below for the dotnet command.
a. Install the C# extensions: code --install-extension ms-dotnettools.csharp
(Optional) Install Mono. Required for some consoles and Android targets(Frameworks 4.5 and 4.7). See here for compatability.
Open a terminal window. Run the following line, either the OS or from VS Code:
dotnet new --install MonoGame.Templates.CSharp
The next two lines may be Linux specific so ignore any uncorrectable errors.
dotnet tool install --global dotnet-mgcb-editor
mgcb-editor --register
At this point, you should be able to create a new CLI project folder from the templates:
cd /path/togame/parent
dotnet new mgdesktopgl -o MyGame
Open the folder in VS Code.
Review the projectname.csproj file:
Note the TargetFramework line:
<TargetFramework>netcoreapp3.1</TargetFramework> or
<TargetFramework>net6.0</TargetFramework>
Some targets require a different TargetFramework, like net47 or net45 as provided by Mono.
See Microsoft's .Net versioning page for more information.
A couple of additional helpful CLI commands to run from the folder with the .proj file; Taken from this list:
dotnet restore Update all NuGet Packages
dotnet clean Remove all output files
dotnet build compile
dotnet run execute the program

How to run an ASP.NET Web Application (.NET Framework) outside IDE?

I used to make REST APIs using the "ASP.NET Core Web Application" template in Visual Studio 2019, but I don't want to have to install .NET Core to use my server application, so I used the .NET Framework template.
However, the former always created an executable file for me to run even outside the IDE. The server would run in a console window. The .NET Framework template however only generates the assembly as a DLL. There is no use in changing to "Console Application" in project settings since the template has no Main() function.
How would I make my server run outside the IDE? I'd love to know how to get the server started from a Main() function. I could then implement a ServiceBase class to turn my program into a service, which is ultimately what I want.
I know that there is a way to "deploy" the server to run with issexpress, but I'd rather have it run itself from an executable.
dotnet run
.NET Core produces a DLL that can be run using dotnet run. For example:
dotnet run MyProgram.dll
Please note: You need the .NET Core runtimes installed if you use this method.
dotnet publish
You can get an EXE stub that will do this all for you by publishing your project. For example:
dotnet publish MyProgram.sln -c Release -r win-x64
That will create a release-mode Windows x64 compilation that contains a file named MyProgram.exe that you can execute normally.
Please note: You do not need the .NET Core runtimes installed if you use this method.
single-file publish
You can even make it easier to distribute by compiling to a single file:
dotnet publish MyProgram.sln -r win-x64 -p:PublishSingleFile=true --self-contained true
That will produce one file: MyProgram.exe.
Please note: You do not need the .NET Core runtimes installed if you use this method.

The 'dotnet publish' command line skips deployment to Azure Functions

I'm setting up some DevOps for my site, and so far I've used the following command for deployment on two ASP.NET Core apps, with success:
dotnet publish ProjectName.csproj /p:PublishProfile="PublishProfileName" /p:Password=password
I've just created an Azure Function, using the V2 runtime and .NET Core 2.1, as suggested for all new projects (see here https://azure.microsoft.com/en-us/blog/introducing-azure-functions-2-0/), but if I use the same command, I find that it only publishes it to a local folder and doesn't seem to deploy the project to Azure.
If I use the MSBuild equivalent, it seems to also miss out the deployment stage.
I'm guessing its to do with the project type in some way not having the appropriate build targets, but I'm not sure how to track this further.
I can download the publish settings from Azure, import them into Visual studio and publish through VS, so it seems like if the VS path works, this might be a regression or bug in the tooling somewhere, rather than something unsupported?
I'm using:
Visual Studio 15.8.8 +28010.2048
Azure Functions and Web Jobs Tools 15.9.02046.0
If I shouldn't be using dotnet publish with Azure functions, what should I be using instead for command line CD? I've seen references to the Azure Function CLI tools, but I'd prefer not to have to install a package manager on our build agents if it can be done through other tooling.
In the end, with the help of the answers and comments (thanks all), I have an MSBuild command line that is working to deploy my .NET Core 2.1 Function project:
msbuild /p:DeployOnBuild=True /p:PublishProfile=somename.pubxml /p:Configuration=Release
It is, however, worth noting the following:
General .NET Core publishing notes
If you miss-spell the publish profile name, it will silently skip deployment (no warning or error).
Differences between ASP.NET Core and .NET Core Functions deployment
If you use 'dotnet publish', it will always skip deployment.
If you don't specify /p:DeployOnBuild=True, it'll skip deployment.
If you do not want to have "a package manager" on your build agents you have to option to make a zip deploy of your function app. Details can be found on the MSDN here:
https://learn.microsoft.com/en-us/azure/azure-functions/deployment-zip-push#rest
Try the Azure CLI instead:
https://learn.microsoft.com/en-us/cli/azure/functionapp/deployment?view=azure-cli-latest
or the function core tools:
https://learn.microsoft.com/en-us/azure/azure-functions/functions-run-local#publish

An assembly specified in the application dependencies manifest

I wrote a .net core console application on mac and it's working fine. Then I made a build for ubuntu by using
dotnet build --runtime ubuntu.16.04-x64
the result was:
MyAppName.Server MyAppName.Server.runtimeconfig.dev.json
MyAppName.Server.deps.json MyAppName.Server.runtimeconfig.json
MyAppName.Server.dll libhostfxr.so
MyAppName.Server.pdb libhostpolicy.so
I copied these files on my linux server and run the following command
dotnet MyAppName.Server.dll
And now I getting
Error:
An assembly specified in the application dependencies manifest (MyAppName.Server.deps.json) was not found:
package: 'Ether.Network', version: '2.0.1'
path: 'lib/netstandard1.3/Ether.Network.dll'
Ether.Network is the only package that I using.
From dotnet build's documentation:
If the project has third-party dependencies, such as libraries from NuGet, they're resolved from the NuGet cache and aren't available with the project's built output. With that in mind, the product of dotnet build isn't ready to be transferred to another machine to run.
You want dotnet publish instead:
The dotnet publish command's output is ready for deployment to a hosting system (for example, a server, PC, Mac, laptop) for execution and is the only officially supported way to prepare the application for deployment.

.NET core CLI -> run ERROR

I have a little bit of problem with dotnet core CLI.
When I am in a project directory and type:
dotnet restore
dotnet publish
It creates published version of my code. And it says that my project is in **PROJECT NAME** -> /Users/**NAME**/hwapp/bin/Debug/netcoreapp1.1/hwapp.dll.
After typing dotnet run it runs my code but when I step to that directory with my dll file compiled and run that dll with dotnet run command i get the following error.
Can some please explain me what I am doing wrong?
dotnet run is a development tool meant to run msbuild projects (e.g. csproj), not execute built applications.
Use dotnet hwapp.dll to run a built application.

Categories

Resources