当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - Windows prompting to install .NET 3.5 when 4.x is installed

问题描述:

I have a small command line application written in C#/.NET. I need it to run when .NET 3.5 or above is installed on the operating system.

To do so, I have the app.config contain the following:

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

<startup>

<supportedRuntime version="v4.0" />

<supportedRuntime version="v2.0.50727" />

</startup>

</configuration>

The project framework is setted to ".NET Framework 3.5".

From my understanding, these two settings should be backwards compatible so that when someone does not have 3.5 installed, but has 4.x installed, it will continue to work.

Is there something else I'm missing? From my research I thought that I had gotten all of the pieces together for this to work.

edit: Per the below question here are also the references and using statements. there are no third party components

the following are references in the project:

System.Core

System.Web.Extensions

System.Windows.Forms

and the following are my using statements:

using System;

using System.Collections.Generic;

using System.IO;

using System.Runtime.InteropServices;

using System.Text;

using System.Security.Cryptography;

using System.Web.Script.Serialization;

using System.Reflection;

using System.Diagnostics;

网友答案:

This is a known restriction of .NET Framework - starting with 4, it does not allow an app to be executed within its own runtime if the previous (in your case, target version) is not installed.

3.5 is based on a different CLR (2.0), hence some compat issues. You'd need to re-target your project to 4.0 (or later) to avoid the issue of the framework install prompt.

Recommended reading: CLR Inside Out - In-Process Side-by-Side

分享给朋友:
您可能感兴趣的文章:
随机阅读: