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.
Related
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
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.
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.
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
I'm required to compile a C# project from the command line (not from within the IDE). It works just fine under linux (to be exact under Fedora and Ubuntu). I just install the mono-xbuild package and the build script is capable of executing the xbuild command. The problem is that there's no xbuild or mdtool inside the home-brew repositories and installing xamarin studio while building isn't the solution because it places the binary in different places depending on a whole range of conditions.
How do I get my build/install script to work out of the box under MacOSX?
You need to install .NET for macOS, then use a dotnet command to run compile and execute a .NET project.
Here are the commands to run a Hello World's app:
dotnet new console -o myApp
cd myApp
dotnet run
For Mono apps, you need to install Mono framework (available as a Mac .pkg file)
Consider also installing MSBuild (The Microsoft Build Engine). It requires OpenSSL (install via: brew install openssl). See: Building Testing and Debugging on .Net Core MSBuild.