Multi-targeting .NET application - c#

I want to write an application that run on windows 7 , 8 , 8.1 and 10 so I targeted 3.5 .NET framework on visual studio ( application name > build > Target framework > Select ".NET Framework 3.5" ) which as far as I know it's the version that windows 7 is shipped with by default (correct me if not) .
after that I added 2 entries to app.config file in visual studio so the whole file became like the following :
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0"/>
<supportedRuntime version="v2.0.50727"/>
</startup>
</configuration>
now is this enough to have my application working on windows 7 and later ? if not enough , how I can achieve this ? I viewed all stack overflow "Similar Questions" but nothing helped
EDIT : I don't want the user to be prompted with .NET download dialog if the .Net framework not found.

It should be enough to make your application run on any computer where either the .NET Framework 4 or the .NET Framework 3.5 is installed.
<supportedRuntime version="v4.0" /> make the application prefer .NET Framework 4.0 if it is installed and <supportedRuntime version="v2.0.50727" /> makes sure that you still support users with only .NET Framework 3.5 installed. You should change the order if you want the application to prefer 3.5:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v2.0.50727"/>
<supportedRuntime version="v4.0"/>
</startup>
</configuration>

Related

How to force WPF app for .NET Framework 3.5 use newer L&F?

I'm thinking of making a simple self-contained .NET application with WPF that can run on any modern Windows system without requiring the end-user to download and install .NET Framework manually.
As far as I know user just need to click on .exe and wait some time until required libraries are installed.
But applications that were compiled for 3.5 use old L&F on most recent Windows.
Is there any way to make applications look like this:
and not like this (if user already has .NET Framework 4+):
Finally I came up with simple solution. My assumption was wrong and it appears .NET Framework actually uses L&F of currently running version, not the targeting one.
Create App.config (Project -> Add -> New Item... -> App configuration (.config))
Paste following:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<!-- Use 4.0 -->
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
<!-- Use 2.0 - 3.5 -->
<supportedRuntime version="v2.0.50727" />
</startup>
</configuration>
.NET Framework will scan <supportedRuntime> until it finds available. List of supported runtimes can be found here.

WIX Installer: .NET 3.5 and .net 4.x

Using WIX Toolset 3.11, custom bootstrapper.
Product has minimum requirements of Windows 7 SP1, all the way up to Windows 10. Another wrinkle is that the machine the user may be installing on may not be connected to the internet to download anything.
The end goal is to have .NET 4.6.2 installed prior to executing the installed product. I have a package in my installer that installs .NET 4.6.2 silently. I didn't use the NetFxExtension, because I couldn't figure out how to include the .NET installer for offline installation (all the redist stuff I tried didn't work).
Here comes the problem:
Windows 7 SP1, the default .NET installation is 3.5.
Windows 10, it's 4.something, 3.5 shows as installed in the registry, but not necessarily in the Add or Remove Programs screen.
When I execute the installer on Windows 10, I get my installer UI.
When I execute the installer on Windows 7, I get "Microsoft .NET Framework required for <application> setup". This SEEMS like it's a problem with the BootstrapperCore.config, which is as follows:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="wix.bootstrapper" type="Microsoft.Tools.WindowsInstallerXml.Bootstrapper.BootstrapperSectionGroup, BootstrapperCore">
<section name="host" type="Microsoft.Tools.WindowsInstallerXml.Bootstrapper.HostSection, BootstrapperCore" />
</sectionGroup>
</configSections>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" />
<!-- I've tried adding <supportedRuntime version="v2.0.50727" /> here too. Didn't work. -->
</startup>
<wix.bootstrapper>
<host assemblyName="ApplicationBootstrapper">
<supportedFramework version="v2.0.50727" />
<supportedFramework version="v4.0" />
</host>
</wix.bootstrapper>
</configuration>
It does get through the detect phase, which starts prior to the UI being displayed (I start the detect, then start the UI).
I've checked all the "Similar Questions" suggested by Stack Overflow, as well as digging around the various WIX bootstrapper websites.
This is the closest thing I've found, but it's for msbuild bootstrappers, not burn bootstrappers.

ICLRRuntimeInfo into my dll - possible?

I have a mixed mode 2.0 dll, and a 4.0 dll. I want to supply this
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration>
to my dll. Without an app.config (or changing machine.config) is this even possible?
You cannot supply this information just for single assembly - the entire application will be executed either on top of 2.0 or 4.0 runtime host.
If the question is how to support v2.0 and v4.0 in application without app.config - see Embedding supportedRuntime into exe file

How explicit is it advisable to be in App.config re: .NET runtime versions?

A little knowledge can be a dangerous thing.
Now that I've had a "run in" with depending on various .NET runtimes being installed on a user's machine, I want to be as "safe" and code as defensively as possible.
However, if I add this to my App.config file:
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v1.0.3705"/>
<supportedRuntime version="v1.1.4322"/>
<supportedRuntime version="v2.0.50727"/>
<supportedRuntime version="v3.0"/>
<supportedRuntime version="v3.5"/>
<supportedRuntime version="v4.0"/>
<supportedRuntime version="v4.0.30319"/>
</startup>
...is it tantamount to wearing suspenders, a belt, AND a cat suit?
(I'm targeting .NET 4 "standard")
No, but are you really using zero features of .NET 2.0+?
Um... There is no 3.0 or 3.5. Just 2.0.xxx and then there is v4.0
Have a look at this msdn link. In particula the first graphic
.NET Framework Versions and Dependencies

Does .net 3.5 Application run on computers without 3.5 but with 4?

I am currently developing a GUI using visual studio 2008 targeting .NetFramework 3.5 I was wondering can a computer without 3.5 but with the latest version(4.0) run the application without any problem or do I still need to install .netFramework 3.5?
You can add the supportedRuntime element to your app.config:
<configuration>
<startup>
<supportedRuntime version="v4.0" />
<supportedRuntime version="v2.0.50727" />
</startup>
</configuration>
I think you need to install 3.5 framework
You need to install .NET 3.5. .NET 4.0 comes with a different CLR, and therefore cannot execute .NET 3.5 assemblies.

Categories