1

I am making a project in Visual studio in C# and when I tried running the built and published project on my friend's computer it gives an error that a certain version of .Net is not installed. I know that you can make projects in C++ and that doesn't require .Net, but I don't want to learn a new language and I mostly get youtube help from people that code in C#. anyone that knows Visual studio, can you tell me if there is a format I can make the project in? for example, Console application, NUnit test project, etc. thx

1
  • 1
    If you target .Net Framework 4.8, it's included in most Windows 10 machines (all consumer machine that receive updates have it. Also all Windows 11 machines). Commented May 24, 2022 at 7:42

3 Answers 3

6

You can publish an application with self-contained enabled. This will build an application that includes all the dotnet framework files needed to run the application.

This does make the application bigger, even the most basic dotnet6 console app on my machines is ~10mb and when it's framework dependent it's 160kb

the settings used in the UI:

enter image description here

You can do this in console with:

dotnet publish -r win-x86 -c Release --self-contained true -p:PublishTrimmed=true -p:PublishSingleFile=true 

Some good docs on trimming and publishing:

https://learn.microsoft.com/en-us/dotnet/core/deploying/trimming/trim-self-contained

https://learn.microsoft.com/en-us/dotnet/core/deploying/single-file/overview

Note on trimmed=true option:

https://learn.microsoft.com/en-us/dotnet/core/deploying/trimming/incompatibilities

Sign up to request clarification or add additional context in comments.

Comments

1

You need to download the framework that your project is using to be developed in and install it on your friends PC. This is normal and with more advanced software engineering you would build an installer that could install it as part of your applications installation.

For now, check what version of the .NET framework your application is build in. You can do this by going to your Solution Explorer window, right clicking on your solution and selecting properties. It will open a new tab menu on the left of your screen and you want to select the Application. In there you will see a drop down menu labelled "Target framework" which shows what framework your project is using, for example ".NET 5.0"

Once you know which framework your project uses, you can go to https://dotnet.microsoft.com/ to download the installer for that framework on your friends machine. Run the installer and once it has the relevant framework, it should run your application fine.

5 Comments

thank you for the advice, but I would prefer it to run offline but I can't find a way for it to
the point of my program is to grab forgotten WiFi passwords, and it not really gonna be fun if every user has to download something
Unfortunetly, C# applications need the client machine to have the framework that their built on installed. Your way around this is to bundle the install with the application itself so they dont need to go online to get it. If you want to do it all automatically, you can download Inno Setup 6. This would let you build an installer script that you could compile the framework installer into with your application and run the setup as part of the install process for you application. But however you do it, the client machine can't run your C# application if it doesn't have the right framework
unfortunately, that is complicated, I will try, thank you
To clear any confusion, the framework installer doesn't need the internet to run. It does run offline so the whole installation would still be offline. I've only said to go online as you've already built the app and installed it on a friends machine. If you downloaded the framework installer on your machine and added it to your build process, then there would be no need for the client's PC (your friends PC) to go online as they would already have the framework installer
0

Additionally to what Istalri Skolir has said, you could also try to optimize for a certain Windows version, by using a preinstalled .NET version.

Here's a list of .NET Frameworks included in specific OS versions.

For example:

Windows 10 May 2019 Update (all editions) includes the .NET Framework 4.8 as an OS component, and it is installed by default

You will need to define the .NET Framework version in the project settings.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.