Cross-compilation with Visual Studio 2019 - c#

I'm using VS2019 under Windows 10 and I'm trying to figure out how to compile for the non-Windows platforms. I'm aware that only some languages support cross-compilation (C# being one of them). So I decided to start off with one of Microsoft's own examples (the Console App for .NET Core). When asking VS2019 to create the Console project, it shows me various image icons which suggest that it'll be buildable for Windows, Linux and macOS - but no matter what I do, I can only make it build the Windows target.
After a bit of research I realized that I need to add this line to my C# project file:-
<RuntimeIdentifiers>win10-x64;osx.10.11-x64;ubuntu.16.10-x64</RuntimeIdentifiers>
but even after adding that line (and re-loading / re-building the project) it staunchly refuses to build anything apart from the Windows target. Over on CodeGuru, one of the devs there tried it for me (under VS2017) and managed to make it work - but I've tried it in VS2019 and also VS2015 and I can't make it work in either of them. Any ideas what I might be doing wrong??
[Edit...]
Thanks Magnetron - if I press Build->Publish I see a totally different dialog from the one you're seeing (and it's the same in both VS2015 and VS2019):-
Even if I follow the Next or Finish buttons I never see the Create Profile option :(

Go to Build > Publish, select Folder and click on Create Profile
Then Click on Edit and change the Deployment Mode to Self-contained. At last, you can specify the target OS in Target Runtime
You can create multiple profiles for each OS, and publish each one individualy as needed.
Edit:
The posted publish dialog is for a .Net Framework Console app, not an .Net Core one. The .Net framework is Windows only, you have to create your project as a .Net Core

Woohoo!! I just ran the VS2019 installer to remind myself how to uninstall (in preparation for tomorrow) and it told me there's already a 16.3.5 available. 16.3.4 only got installed a few hours ago but for the hell of it, I figured I might as well try the newer version - and it's now working !!!

Related

Setting up my WPF solution and the "Project doesn't know how to run the profile" error

I've created a solution in VS2022 using the WPF application template (not the one that says (.net framework)) and when trying to run it I get the error popping up:
"The project doesn't know how to run the profile with name 'wpftestproject' and comment 'Project'."
See the image below, it's not an output window error but an actual pop-up window.
I'm on Windows 10 pro and trying to get this template solution to run (it should pop up a MainWindow).
I have no idea what could be the source of this issue and I'm not finding anything online.
One thing I noticed is that under application properties the "Target framework" is default to .NET6.0 and not .NET CORE 3.0 for some reason. Though changing this isn't fixing it.
I've also tried having a look over my VS installation, it doesn't seem to me that anything is missing but maybe someone else knows something:
Normally you need to install correctly, .Net desktop development and universal windows platform development.(Try to reinstall .Net desktop development)
And install the packages you need in individual components.
If reinstalling these does not help you, I suggest you choose update->repair

WPF .net Core 3.1 application deployment tools for any platform?

I have a utility editor application that goes with another main application. The main application is a Windows EXE usually, but there is also a Unix and a Mac version. This application was written by another company for us. It is not C#.
We have a utility editor program that works with the main application. The original version is a WinForms app, but it is showing it's age and some of the functionality no longer works on today's Windows. So the app is being rewritten in WPF with .NET Core 3.1, with the hope that maybe we will also compile it for Unix and Mac someday, if possible. They want it to be a stand-alone app so it can more easily be used by students at different universities and other organizations. Click-Once, MSIX, and copying larger folders are not options. They want a standalone EXE(s) they can upload/distribute for 32 and 64 bit Windows initially, often sent on DVD.
But I am having build issues for WPF. I have tried to publish the app, and the VS Installer add-on, but they were failures, which appears to be the common complaint on the internet. For some reason, you always end up with a DLL application instead of an EXE, and it doesn't run and I am not alone per the discussions on the internet. I am thinking is has something to do with the .NET Core but I just don't know enough about it to know how to resolve it. One article hinted that the DLL might be the portable part, and then you need a platform specific module that runs it??? Did I misunderstand that? If so, How do I create one?
I am now looking into third party tools. It appears Wix might be worth exploring, but the learning curve is billed as large, so the boss is nervous. I am also not sure about the Unix or Mac builds. Will those be different tools yet again?
According to this it probably is, but this is 2 years old:
How to build installers for .NET Core app?
Has anyone been successful in building a WPF .NET Core 3.1 setup.EXE that actually installs a usable application? If so, what tools did you use? Can you provide any advice for what I might be missing? I can get the setup.exe, but the app that it installs is not usable.
I would be ever so grateful for any help you can provide. This community has been SOOO helpful to me for many years and I can usually find the answer from previous questions without ever asking anything myself. So I have no rating. But I have been a user for over 10 years! Please don't hold that against me? But this time I am stumped. It could just be I am tooo new to .NET Core (first app in it) and I don't have the right search terms. I am usually a Web developer. But Web is not an option here.
Thank you for your consideration,
MLY
A bit late, you might have already figured out a solution, but for anyone else wondering.
One way is to use ClickOnce.
If using Visual Studios, you should be able to right click your main project and select "Publish". Then you should be able to click "New" publish profile. From the options that come up you can either select "ClickOnce", and then you should be presented with some settings. For you, most importantly, would be two of those tabs, "Install location" and "Configuration". In the former you can choose "From cd/dvd, or usb" since you mention that is a method of delivering the executable you will need.
And in the latter, you can select "Deployment mode" to be "self-contained", and under "File-publish options" choose "Produce single file".
This should ultimately produce an EXE for your application that can be used as a standalone.
Note that using VS19 there are some issues that seem to not allow this to happen https://github.com/dotnet/sdk/issues/11351
However using VS22 this does not seem to be an issue, I at least have not experienced it there.
For more information
https://learn.microsoft.com/en-us/dotnet/desktop/wpf/app-development/deploying-a-wpf-application-wpf?view=netframeworkdesktop-4.8
https://learn.microsoft.com/en-us/visualstudio/deployment/quickstart-deploy-using-clickonce-folder?view=vs-2022
Also, F.Y.I, WPF applications only run on windows, so you wont be able to deploy them on Mac or Unix at all. There is some community support for using Xamarin.Forms with WPF, but if you need multi-OS deployment you should not start developing this application with WPF in the first place.

Unable to change Platform Toolset Visual Studio 2015

I have a C# solution in Visual Studio 2015 with two projects, the applications run perfectly on Win 7 and up however, they will not run on XP. I've done the mandatory research and seen that I need to update my Platform Toolset setting and include a few dlls, however, when trying to follow the steps (as listed on this site and MS's) I do not see the options for configuring this.
An similar question on this site showed a screenshot with an example but when I try to navigate to the configuration options for this project (not solution) I do not see the "Platform Toolset" setting, much less anything else shown on the example.
Firstly, viewing the property pages of one of the projects shows an entirely different UI with no "Configuration Properties" and the only way for me to view a form similar to the example is to view the properties of the entire solution (against MS instructions)
Example
My Project Property Page
My Solution Properties
As you would see, the dialog does not offer a "General" tab and neither of the projects within the solution have the ability to view the configurations.
I've inherited this application and am not sure what was done during the creation of the solution and projects that may have caused this. Any ideas? Is there something that was done incorrectly?
Your example is from a C++ project, whereas your project is a C# project, hence why the two look completely different.
Windows XP does not support .NET 4.5, so you will have to downgrade to an earlier version of .NET (Source).
The drop-down to do this is clearly displayed in your "My Project Property Page" screenshot (labelled as "Target Framework"). The latest supported version for XP is .NET 4.
It is worth noting that Windows XP is no longer supported by Microsoft (unless you are paying for extended support - and even that runs out in a year or so). It is not recommended that it is used.

DotNetBar c# app crash when opening in another pc

I created a c# app just to test the DotNetBar components it works perfectly in my computer but when i sent it to a friend to tried the app crashes instantly.
do I have to move some dll files or something.
thanks
This problem is from the dotnetbar dll not being present on the second machine. There are two solutions that allow programs with dotnetbar to run on machines that do not have it.
You can go to references and change copy local to true (solution OP mentioned in comment on other answer). This includes the dll in every build which, in some situations, can make debugging builds more time consuming.
OR
You can go to Publish, open the Application Files window and change the Publish Status to Include. This will only include the dll when you publish instead of every build (generally more recommended option).
note: both of these are done from the project properties
I suspect that you have developed your Application in heigher version of .NET Framework and trying to run it on your friend mavhine which does not have the same.
Solution: try to find the .NET framework version which is being used by your friend and then target your application to the same version.
Follow the below steps to change the Taget Framework version.
1.RightClick on Your Project
2.Select Properties
3.Now Select Application Tab
4.Select Target Framework Version dropdown
5.Select the .NET Framework version xyz [here xyz is the .NET framework version used by your friend]

Deploying C# (.NET 2.0) application as a portable application?

Is it possible to deploy a .NET 2.0 application as a portable executable?
So that my program can be ran in a Flash Disk without the .NET Framework 2.0 installed in the target machine. Or maybe is it possible to distribute my program with the required .NET DLLs, so that no framework installation is necessary?
I know that there are some alternative tools to turn my .NET exe into a single native executable like RemoteSoft Salamander, Xenocode Postbuild, and Thinstall, but unfortunately I can't afford one.
I also tried to embed the dependencies with Mono's mkbundle, but it messed my program up =\ (no XP visual style, broke some controls and its functionality)
Any kind of help would be appreciated :)
Thanks.
fyi: my IDE is Microsoft Visual C# 2008 Express Edition with .NET Framework 2.0 as the target framework.
Well, other than things like Salamander and Thinstall (now VMWare ThinApp) you would have to have .NET installed if you really want to run .NET.
It may be possible to run Mono without actually installing it (not statically linking your program, but including Mono on the flash drive). I suspect it would be tricky though, as you'd have to tell the runtime about things like the GAC location.
I can't see anything in the Mono FAQ about this, but you might want to ping a Mono mailing list - it sounds like a potentially interesting and useful thing to be able to do.
No; you need either the framework installed, or the tools like you have mentioned.
You could potentially look at mono's new static linker, but that is about it...
I have not tried this myself but here's the procedure:
Make a C# project.
In Solution Explorer, inside your project, there is a line "Reference". Click the plus near it. Now you can see all the dependencies of your project. Delete all references that aren't used (delete, and try to run/build. If it is possible to do it, that it is unused. If there is an error, return it by adding it (right mouse click, "Add Reference")).
For each reference, go to Properties, and in the property "Copy Local" choose "True". For each Image, Icon... make like to the referenced.
Rebuild you project. Now in your Build/Release folder (inside bin) you will see many dll files. Those files have the information of every resource.
Copy all the files in the folder (from step number 4) into a new folder.
Go to the folder: "\Microsoft.Net\Framework\" and copy the file "mscrolib.dll" to the new folder from step 5. If you don't find this file, you can always make a search in the Hard Drive which contains Windows folder.
Now your app is portable (with the whole folder content).
-- Source: http://www.codeproject.com/Tips/392308/Csharp-Portable-Exe-File
Well Thinstall is very expensive and it doesn't work in all situations. If you want to run your app without .Net installed you might run into trouble although there are tools that do that Xenocode has a tool that can do this for you and it's cheaper than thinstall.
But if you ask my opinion it's a bad idea to use them. Better convince your target market to install .Net 2 (Which is pretty much universal these days), and then pack all of your library files into one file using a cheaper Obfuscator like tool (There's a good one from Smartassembly.)
I've used Thinstall for a long time, and I've worked on this technology a lot, so I am not shooting off without experience.

Categories

Resources