C# Program doesn't work on other computer - c#

I have made an application that connects to a server and listens to certain packets, I used Nuget network library for that. Here is my .csproj file:
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>remote_client</RootNamespace>
<Platforms>AnyCPU;x64</Platforms>
<UseWPF>true</UseWPF>
<UseWindowsForms>true</UseWindowsForms>
<StartupObject>remote_client.client</StartupObject>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Network" Version="6.1.4.20" />
<PackageReference Include="System.Management.Automation" Version="7.0.0" />
</ItemGroup>
<ItemGroup>
</ItemGroup>
</Project>
Then I had problem how to compile it into a single .exe file. I found a command I used in powershell (I ran it in project's directory):
dotnet publish -r win-x64 -c Release /p:PublishSingleFile=true /p:PublishTrimmed=true
And then I had a single file I could use anywhere on my computer.
When I tried to give it to my friend, it wouldn't work with error from Windows (my translation): Can't run this application. Ask program's developer to do something...
My windows version is 1909 and his is 1809.
So summarizing, I need to fix the issue or get some easy way to publish a application and compile it into a windows-universal single .exe file.
EDIT: actual error message is:
This application will not work on your computer. To find the version for this computer, contact the software publisher.
First sentence is caption of the popup message box, second sentence is being displayed as message.

My bad, I think that it couldn't work because the computer my friend ran the application on was 32 bit but I compiled it for 64 bit.

Related

GLIBC_2.2.5 not defined in file libpthread.so.0 with link time reference

I'm creating a C# app which I have build or as they call it "published" for linux-x64 following this XML in the csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<Configuration>release</Configuration>
<InvariantGlobalization>true</InvariantGlobalization>
<TargetFramework>net5.0</TargetFramework>
<PublishSingleFile>true</PublishSingleFile>
<SelfContained>true</SelfContained>
<RuntimeIdentifier>linux-x64</RuntimeIdentifier>
<PublishTrimmed>true</PublishTrimmed>
<PublishReadyToRun>true</PublishReadyToRun>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="mongocsharpdriver" Version="2.11.6" />
<PackageReference Include="MongoDB.Bson" Version="2.11.6" />
<PackageReference Include="MongoDB.Driver" Version="2.11.6" />
<PackageReference Include="MongoDB.Driver.Core" Version="2.11.6" />
<PackageReference Include="PCSC" Version="5.0.0" />
<PackageReference Include="PCSC.Iso7816" Version="5.0.0" />
</ItemGroup>
</Project>
I'm on Linux Ubuntu 20.04 .
I published the application using CLI to the folder bin/release etc etc. It ran just fine when I tested it. Now, for the main branch, I deleted all code. Moved the directory release up in the main directory, and pushed it to GIT.
Whenever you try to run it now, it gives the following error:
./Appname: relocation error: ./Appname: symbol pthread_attr_init version GLIBC_2.2.5 not defined in file libpthread.so.0 with link time reference
As I'm not a native C# developer and still learning, I have absolutely no idea what this is about, except it apparently has something to do with me moving the directory (I quess?)
Does anyone know what this error is or where it comes from, how to fix it, and how to prevent in the future? As I would like to be able to publish an application without errors.
solved
I Found the answer. There is another directory within the build directory called "publish" which contains the working executable. In other words. The exe is in the folder release/net5.0/linux-x64/publish instead of release/net5.0/linux-x64. When I run the executable from that directory, everything works just fine. For other newbies: It is in the folder release because my XML project file has a Configuration field set to release. It is in the folder Debug by default.

PublishSingleFile does not produce a single executable

I have a .Net Core 3 console application that i'm trying to publish as a self contained single executable. I've been able to do this in the past but to my suprise it no longer works. The project structure is a console application with two assemblies, all in Core 3.
If i use dotnet publish -r win-x64 -c Release /p:PublishSingleFile=true /p:PublishTrimmed=true i expect the output to be a single executable of several mb's in size. However the publish folder contains the executable (few hundred kb) and a .dll file together with .cache files and the pdb.
The config for my console app is as follows:
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<LangVersion>latest</LangVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Nullable>enable</Nullable>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<PublishSingleFile>true</PublishSingleFile>
<PublishTrimmed>true</PublishTrimmed>
</PropertyGroup>
If i publish the app directly from Visual Studio i get the same results as above.
So my question boils down to: Why doesnt this configuration or publish statement result in a self contained single executable?
I can get my 3.1 console app to publish with the following:
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration>Release</Configuration>
<Platform>Any CPU</Platform>
<PublishDir>..\..\Binaries\</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<PublishSingleFile>True</PublishSingleFile>
<PublishReadyToRun>False</PublishReadyToRun>
<DebugType>None</DebugType>
</PropertyGroup>
</Project>
If I set PublishReadyToRun to True (or add PublishTrimmed as True) it fails. Adding DebugType None prevents it publishing the pdb file for the exe.
UPDATE: removing the SelfContained tag stops it creating the 'dotnetcoreapp3.1' folder.
According to the command line release, I tested successfully. A single executable file was generated. If you have always failed to publish, I suggest you use VS to publish.The publishing process is as follows:
1.Right click on the project->publish
2.Change configuration
3.Save the configuration and click Publish

How to publish a full self-contained .NetCoreApp as exe?

I'm trying to publish an usable exe-file of my C# .NetCoreApp2.2 console application.
I have written a little application in C# using the Visual Studio Code IDE. I started by typing dotnet new console and opened the project within Visual Studio Code. I installed some third-party-libraries like log4net and DocumentFormat.OpenXml.
I can debug my application within Visual Studio Code - no problems. I can run dotnet run within the project source directory - no problems. I can also run dotnet publish -c Release -r win10-x64 --self-contained true without any problems.
After the publish command I get the expected .exe-file (and a lot of other files?) within the expected subdirectory.
Now to the problem:
As soon as I try to execute the .exe-file I get an unhandled expection.
I do have third-party-libraries referenced, but as I understand it, the self-contained option should take care about that - does it?
I have googled and saw some results describing the publish-process talking about a project.json - file which I do not have. Also people describe that this file will be created using the given dotnet-command. For me it never will be created using that command - any additional flag to set?
This is my .csproj-file
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="log4net" Version="*" />
<PackageReference Include="Nunit3TestAdapter" Version="3.13.0" />
<PackageReference Include="NUnit" Version="3.12.0"/>
<PackageReference Include="System.Configuration.ConfigurationManager" Version="*" />
<PackageReference Include="DocumentFormat.OpenXml" Version="2.8.1" />
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.0-beta0006" />
</ItemGroup>
</Project>
Might the "*" for version be a problem?
I would expect to get a single .exe-file (which might be huge) that executes and shows the same output as I will get using the command dotnet run within the source-directory of my project.
Any Ideas?

C# dependecies aren't being included with publish

I'm trying to publish a web API built in .NET Core to a Ubuntu server but am having difficulty with the dependencies. I am new to doing this in C# and haven't found a concise answer to how dependencies are included with the publish command. I was lead to believe that they were complied into a .dll but I am getting this error when running my app
Error:
An assembly specified in the application dependencies manifest (api.deps.json) was not found:
package: 'Newtonsoft.Json', version: '11.0.2'
path: 'lib/netstandard2.0/Newtonsoft.Json.dll'
Shouldn't that have been included in the "Release" directory after being published?
I'm using .NET Core on a Mac and then publishing to an Ubuntu sever should that affect anything here.
.csproj:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
</ItemGroup>
</Project>
Shouldn't that have been included in the "Release" directory after being published?
No.
When you publish a project, you specify a different directory for the publish output when creating the publish profile.
The Release directory is only for assets that are used during debugging. During development, the NuGet dependencies are not in the Release folder, they are in the NuGet cache. So, you cannot always just copy the Release folder and expect it to run.
After publishing, the entire application (including all dependencies) are output to the publish location. Do note that the publish output doesn't necessarily have to be a folder. For example, depending on the type of project it may be published to IIS with web deploy or to an FTP location.

Self Contained EXE not finding correct path on OS X

So I've made a self-contained release of a project with Visual Studio Code. The EXE is working on ubuntu and windows, but can't get it to work on os-x.
I'm using a simple data.json to store some data. The error that occurs on the os-x release, is that it can't find the correct path to data.json. I get this message:
Could not find file '/Users/User/data.json'.
That is not where I store the release or data.json. I store it in the root-directory of the project. Seems like the application is looking for the json-file in my system root directories. How do I fix this?
My XML csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.1</TargetFramework>
<RuntimeIdentifiers>win10-x64;osx.10.11-x64;ubuntu.16.10-x64</RuntimeIdentifiers>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.json" Version="10.0.3" />
</ItemGroup>
</Project>

Categories

Resources