i am using visual studio 2017 with .net 4.8 and when i hit publish the option for Self-Contained app or Single File option doesn't show and i tried opening the project with Visual Studio 2020 and still the option doesn't show.
this is a WPF application
Publish Wizard Screenshot
Publish Wizard Screenshot
Publish Wizard Screenshot
Publish Wizard Screenshot
According to the official documentation.
This deployment model has been available since .NET Core 3.0 and has been enhanced in .NET 5. Previously in .NET Core 3.0, when a user ran your single-file application, the .NET Core host first extracted all the files into a directory before running the application.
.NET 5 improves this experience by running the code directly without extracting files from the application.
So the answer to that question is, you can't use single file publishing under .net 4.8.
Related
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.
I've created a simple .NET core console app targeting .NET Core Framework 1.1. When I build it, it creates an assembly file named DotNetCoreConsoleApp.dll in the \bin\debug folder. So there is nothing that I can double click and run directly but interestingly when I start debugging the project by pressing F5 then Visual Studio is able to launch a process.
Project configuration of my project is as below:
How windows will be able to launch such an application process without any exe file? I understand that Windows only understands a file as starting point of a process if it contains PE header.
There is no exe file.
From msdn:
"Short answer, there isn’t one. When you compile your .NET Core console application for example, you get a DLL. Then you execute it using the DOTNET command from the .NET Core SDK found here."
From a different answer on stackoverflow (Visual Studio 2017 missing exe file):
You have two options:
If you want an EXE, you need to target the .NET Framework.
If you don't want to change your code, then you need to install .NET Core on the server and run dotnet pathToDll on a command line
https://blogs.msdn.microsoft.com/benjaminperkins/2017/03/07/net-core-application-where-is-my-exe-how-to-publish/
I am trying to update my project to .net core 2. But I am facing issues I have no option in the target framework to change to
I installed the .net core 2 sdk from the download site
I also tried the suggestion here but did not work for me
.NET Core 2.0 missing from my Visual Studio
But when I try to modify visual studio to install release 3 i get the following
this happens even if I click the installer and i DO NOT no why I tried various suggestions Including delete this folder
Try deleting %LocalAppData%\Microsoft\VisualStudio\Packages_Channels
But it does not exist on my pc I am running windows ten by the way
As I can see there is global.json file in your project. Try changing sdk version to 2.0.0
I am trying to link a local ASPNET Core application to SonarQube through the team explorer connection.
My ASPNET.Core project has been recently updated to the latest version of dotnet core and also has a .csproj file. I am developing in Visual Studio 2017 with the latest version of C#.
Whenever I try to bind to my SonarQube instance (v6.1) I am prompted to authentication which I provide. Once logged in an attempt to download the compatible projects fails with the error
I also get the following output in sonarLint window
Any ideas on how I can make SonarQube recognise this project so I can bind it?
SonarLint Connected Mode is not yet available for .Net Core projects, you can track progress on GitHub issue #151 .
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.