Home > Mobile >  how to make project without .Net?
how to make project without .Net?

Time:05-24

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

CodePudding user response:

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://docs.microsoft.com/en-us/dotnet/core/deploying/trimming/trim-self-contained

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

Note on trimmed=true option:

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

CodePudding user response:

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.

CodePudding user response:

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.

  • Related