how to make project without .Net? - c#

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

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:
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

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.

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

Published .Net Core App Warns to Install .Net Core but it's Already Installed

I made a WPF and Console application for someone to use on their private server which I can't have access to. I used Visual Studio 2019's built-in "Publishing Wizard" to create Framework Dependant single-file apps. When the person opened the WPF app they were greeted with the standard warning:
They clicked yes and to my understanding, they installed .Net Core 3.1 which is what the applications target.
After they restarted the computer they got the exact same warning again. I wasn't sure what was going on so I repackaged the apps as self-contained since the installed version of .Net Core was the same as what my applications were targeting.
That seemed to work for a little bit. We ran into some unrelated issues that I had to fix in the code on my end and then I re-published the projects and sent them out.
They tried to use the WPF application and they got the install warning again.
Now no matter what combination of options I pick in the "Publish Wizard" they keep getting the warning.
I'm not sure what to do.
Here's a picture of my publish settings
In my case I had the same issue, and the problem was that I was not deploying the file "MY_PROGRAM_NAME.runtimeconfig.json". After copying this file, which is present in the build output, the application is launched without problems.
Turns out the issue was the fact that the applications were targeting win-x86 and the user only had access to 64-bit runtimes of .Net Core.
For some reason, I thought it would be able to handle a 32-bit version even if it was running 64-bit runtimes.
I guess live and learn.

Publishing VS project: Installer requires .NET 4.6.2

I am trying to make a simple Windows Forms app that communicates with Arduino.
As this is my first WinForm application, I am currently stuck on the publish process.
I manage to publish the app with a installer, but, when I open the installer, it asks for the .NET Framework 4.6.2 to be installed.
I tried targeting the .NET 4 version on my project, but the installer keeps requiring the 4.6.2.
Do you know how to solve this? OR is this maybe due to the installer itself needing the 4.6.2 framework?
Thanks,
did you change the .net version required on the installer project ? if not, you should check your launch conditions (right click your project → vies → launch conditions). There you can right click ".NET Framework" and chose properties. In the properties window you can adjust your .net version required.
I'm assuming you use the installer projects from the "Visual Studio Installer Projects" extension.

Building a .NET Core app via command line, so that it works on a machine without .NET Core installed

My end goal is to create a cross-platform (non-web) console application, so I'm exploring .NET Core right now.
In my previous .NET projects, I did all the development inside Visual Studio, but I also created a batch/MSBuild file so I could build the whole project (including setups, NuGet packages, zip files with binaries etc.) with one single click. Here's an example from a previous project.
In the end, I want to do something similar with my .NET Core test project.
But right now I'm failing at the first step: I'm unable to build it outside Visual Studio, so that the result works on another Windows machine without .NET Core installed.
(in the first step, I'm ignoring the cross-platform part - I'll be happy to get it to work on Windows)
What I have
I managed to get it to work inside Visual Studio 2015 Community Edition as follows:
create new project in Visual Studio: "New Project" ⇒ "Web" ⇒ "Console Application (Package)"
create new publish profile inside Visual Studio ("Build" ⇒ "Publish" in the menu).
This will create a PowerShell script (and an XML file with settings)
Here's my test project on GitHub.
When I do "Build" ⇒ "Publish" in the menu again, Visual Studio apparently executes the previously created PowerShell script again.
The result is slightly over 90 MB, consists of 825 files in 598 folders, and looks like this:
When I copy it on another machine (Win 7 / .NET 4 installed / .NET Core not installed), it works.
What I tried to get the same result outside Visual Studio
1. dotnet publish
This answer and this answer sound like I can use dnu publish to achieve the same result via the command line.
I understand that parts of .NET Core are still moving targets right now, so apparently dnu is now dotnet instead.
So I tried to execute dotnet publish (and created a batch file) for it:
dotnet publish "%~dp0\src\CoreTestVisualStudio" -c Release -r win7-x64 -o "%~dp0\release\cli"
The result consists of an .exe file and a bunch of DLLs, only 25 files and 1.5 MB, all in one single folder:
Obviously the .NET Core runtime is missing here, and as expected, this app crashes when I try to execute it on a machine without .NET Core installed (the same one as mentioned above).
2. The PowerShell script from the publish profile
I tried to execute the PowerShell script (which was created when I created the publish profile) outside Visual Studio, but it failed because the script expects some parameters and I don't know what to pass:
param($publishProperties, $packOutput, $nugetUrl)
There's also this line in the script:
# to learn more about this file visit http://go.microsoft.com/fwlink/?LinkId=524327
...but the link just points to the landing page of the .NET Web Development and Tools Blog.
TL;DR
What am I doing wrong?
I know that the first release of .NET Core mainly focuses on ASP.NET, but as I understood it, ASP.NET Core apps are just console apps as well, so I thought a basic console app would work now.
On the other hand, most of the console app "getting started" docs are still missing, so maybe it's just too early and dotnet publish for console apps is not finished yet?
Edit after a few days: I'm suspecting that I'm doing nothing wrong and that it's an issue in the.NET Core command line tools, so I posted it to the command line tools' issue tracker.
Problem solved!
I posted it on the issue tracker of the .NET Core command line tools, and it turned out that it was a bug in dotnet publish - it didn't bundle the C++ runtime, which is needed to execute the compiled app on a machine without .NET Core installed.
The temporary solution was to install the C++ runtime.
The "real" solution was made in a pull request three days ago, which is included in the latest installer now.
With this version, dotnet publish does bundle the C++ runtime, so the result will work on a machine without .NET Core.
For dnu:
There's an option for dnu publish called --runtime that specifies the runtime to include when publishing. You would use the full runtime name with the command, e.g.:
dnu publish --runtime dnx-clr-win-x86.1.0.0-rc1
For dotnet:
You don't need to specify the runtime or framework versions -- by default, dotnet publish will use the framework from project.json and the current runtime flavor. However, the documentation states that:
dotnet-publish command also requires certain dependencies in the project.json to work. Namely the Microsoft.NETCore.Runtime package must be referenced as a dependency in order for the command to copy the runtime files as well as the application's files to the published location.

.NET Application is targeting 4.5, Setup.exe says it requires version 2.0.50727

I'm working on upgrading a windows application/service to target newer .NET frameworks for a client. This is the first time I've done anything of the sort. I changed the Target Framework in the C# project's properties window to 4.5, rebuilt the project without any errors, and then tried to run setup.exe. When I run this, it says:
This setup requires the .NET Framework version 2.0.50727.
Does anyone know why this would be happening? I read about launch conditions and that it could possibly be checking that the client computer requires v2.0, but I don't see an option to view the launch conditions in Visual Studio 2013.
Thanks

Does Visual Studio ClickOnce deployment automatically include the necessary .NET framework?

When using a ClickOnce installer, will it include the necessary .NET framework?
For instance, I want to distribute a WPF application that uses the System.ComponentModel namespace, which wasn't included until .NET 4.5. If I ran the ClickOnce on an older version of Windows that only had up through, say, .NET 3.0, would it still work?
The click once application will depend on the .NET 4.5 framework. You can include this as a redistributable through project settings -> publish -> prerequisites. In fact I think recent VS versions will already prepare a setup package to run through installing this during the pre-reqs section of your installer. You can even alter the location of where the redistributable package comes from.
In summary. It will "work" in that when someone runs your installer it will tell them they don't have the correct pre-reqs, and offer to install .NET 4.5
It will, if you install with the setup.exe installer. I haven't tried it for some time but it always worked like this.
If you link directly to *.application manifest, the .net framework and other dependencies will not be installed automatically.

Categories

Resources