Create via VS2017 preview a .net core 2.0 console app.
Run it, x64, no problem.
Switch properties-> build -> platform to x86
Run it, run hangs and gets nasty message about it not working.
Drop out to command prompt
Navigate to directory where project is
Delete bin and obj
dotnet restore
dotnet run
Get a System.BadImageFormatException.
Any ideas how to build and run this? Tried installing 32bit framework, no go.
1.Install x86 DotNET core run time on your machine. its default location is
C:\Program Files (x86)\dotnet
2.update your web.config file
make sure the process path point to x86 version DNC
Install dotnet X86 Runtime from https://dot.net
Related
I am trying to publish a C# .net core console app I made, to a Linux machine running Centos 7 64 bit. Currently, I am publishing the app using the command:dotnet publish -c release -r contos.7-x64. Unfortunately, it appears as though publishing in this way requires .net core to be installed on the target machine. Is it possible to do this where I do not need to install anything on the machine that I am publishing to?
In .NET Core 2.2 you can create a self-contained app (i.e. not requiring .NET Core runtime installed on host machine) with this command dotnet publish -r centos.7-x64 -c Release --self-contained. It'll produce executable and a lot of dependencies.
In .NET Core 3 you can compress all dependencies into a single file dotnet publish -r centos.7-x64 -c Release /p:PublishSingleFile=true. You can also add flag /p:PublishTrimmed=true to reduce executable size by tree trimming.
More details can be found here and here.
I found that the issue was that the project was not compiling to core 2. Rather, the project was compiling to version 1. After making this change, the published project was able to run on Centos.
In .NET framework when we build our solution/project, we get an exe in the debug/release folder and we can run our application by double clicking that exe. But how can we do this in .NET core, i know we can't have an exe in .NET core because it is windows specific. When i build my .NET core application i get the following files in the debug folder.
I know how to run this application using command prompt but i want to have a file like exe by clicking which i can run my application.
You can generate exe (self-contained application).
.NET Core 2.0 +
Open Package Manager Console or any other console in your project directory and type:
dotnet publish -c Release -r win10-x64
dotnet publish -c Release -r ubuntu.16.10-x64
When you use previous version of .NET Core you have to add runtime identifier of the target environment in csproj:
<PropertyGroup>
<RuntimeIdentifiers>win10-x64;ubuntu.16.10-x64</RuntimeIdentifiers>
</PropertyGroup>
Runtime Identifiers (RIDs) list:
https://learn.microsoft.com/en-us/dotnet/core/rid-catalog
One simple solution is to create a .bat file with runs the dll via the dotnet cli, then you get "a file like exe"
dotnet ConsoleApp2.dll
I created a .Net core C# console application in Visual Studio and used the following steps to test it on Linux.
Use Visual Studio "Build -> Publish" menu item to create the executable files in ....\bin\Release\netcoreapp2.1\publish.
Copy the "publish" directory to the Linux machine
On Linux, chmod 777 myApp.dll
./myApp.dll
However, executing the app shows the error of
-bash: ./myApp.dll: cannot execute binary file
It looks like you did a Framework-Dependendent Deployment. Essentially, the publish command was:
dotnet publish -c Release
FDD assumes that you are going to have a .NET Core runtime to run your application on the target platform.
Once you copied over the publish directory to another machine (which could be Linux, macOS or Windows), your application still needs a .NET Core runtime to run your application.
Installing the .NET Core runtime depends on the particular Linux distribution that you are using. Once you have it installed, you can run your application by doing:
dotnet /path/to/publish/myApp.dll
An alternative to Framework Dependent Deployment is Self-Contained Deployment. In this mode, the published application will contain your application as well as a copy of the .NET Core runtime. On command line, doing a a SCD publish looks like this:
dotnet publish -r linux-x64 -c Release
For doing this in Visual Studio, see the link above. Then, you should see a bin\Release\netcoreapp2.1\linux-x64\publish\ directory that contains a myApp file. You can copy over this publish dir over to a Linux distribution and just run:
/path/to/linux-x64/publish/myApp
I'm developing a .NET Core app on a Windows 10 machine (with Visual Studio 2015 update 3 + Microsoft .NET Core 1.0.1 VS 2015 Tooling Preview 2) which should published on an Ubuntu 16 machine. To do that, I have to move my source code to the end machine and compile it there, to get it to run. e.g. I'm not able to compile the code on windows and run it on linux. Question: Is there any way to compile the code on win machine and run it on linux?
Using dotnet build command, you may specify --runtime flag
-r|--runtime < RUNTIME_IDENTIFIER >
Target runtime to build for. For a list of Runtime Identifiers (RIDs) you can use, see the RID catalog.
RIDs that represent concrete operating systems usually follow this pattern [os].[version]-[arch]
Fo example, to build a project and its dependencies for Ubuntu 16.04 runtime use:
dotnet build --runtime ubuntu.16.04-x64
dotnet publish **path to your solution** --configuration Release --framework netcoreapp3.0 --output .**output path** --self-contained false --runtime linux-x64 --verbosity quiet
For anyone who's now seeing this not working anymore, it seems as of the update on the 10th of November 2020 you have to specify the project file now as it doesn't like using a specified runtime on a solution (.sln) anymore.
An issue about this was raised here (https://github.com/dotnet/sdk/issues/14281) but obviously that's not going to get resolved immediately.
So previously where this would work:
dotnet build --runtime ubuntu.xx.xx-x64
It wants something like this now:
dotnet build ProjectName.csproj --runtime ubuntu.xx.xx-x64
Option 1: Command line
dotnet build ProjectFile.csproj --runtime linux-x64
Works on Linux and Windows and Mac.
Option 2: Visual Studio
You can also "publish" your app in Visual Studio if you prefer. Choose "File System" publish method and set this setting:
In these days I'm trying these projects:
- Visual Studio Code: I chosethe portable (.zip) executed from USB memory.
- .Net Core (.zip package again), which I decomprissed into the same USB memory as the previous one.
When I try to generate a new C# into VSCode project, first I had the problem around how to invoke the .Net core folder (aka dotnet decomprissed folder). Until now, just I had to put in the console the absolute path location of the dotnet executable -again, from the folder I decomprissed from the zip file-.
But then I try to debug the console application after these commands:
dotnet new
dotnet restore
dotnet build
I see the following error:
The .NET Core Debugger is still being downloaded. See the C# Output Window
for more information.
[ERROR]: C# Extension failed to install the debugger package
How can I solve this?
Just saw this error on my PC too, turns out as of now the C# debugger doesn't support 32-bit Windows system, there is an issue on GitHub: https://github.com/OmniSharp/omnisharp-vscode/issues/844.
Check if you are using a 32-bit Windows, if yes, upgrade to x64.