简体   繁体   中英

Set target framework to 4.5

I have a small project which needs .net version 4.5 because of Compression. This is my App.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>   
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/></startup>
</configuration>

But when I try to run the program on a stock Windows 7 system, it says that I need to install v4.0.30319. This way the user have to install v4.0 first, THEN the v4.5. Is there a way to set it so it will need v4.5 by default?

I'm using VS2015 if that changes anything

Apparently, according to the MSDN article on <supportedRuntime> ( https://msdn.microsoft.com/en-US/library/w4atty68(v=vs.110).aspx ), your current solution is the correct way to check the version. It seems the .NET 4.0 Update 3 Framework is required as a base for any future versions. But this is an assumption, I'd be happy to be corrected here.

Update : I did a litlte research, and .NET 4.5 effectively replaces .NET 4.0 on the system. In accordance to the article I mentioned, it seems that everything from .NET 4.0 and above seems to be identified with a version string of "v4.0.30319" in the metadata of the assemblies, hence the .NET loader will always think that version has to be installed first.

BUT since .NET 4.x replaces the old one, I would assume that you can install .NET 4.5+ directly without the need to install .NET 4.0 first.

In short: I assume that you can install .NET 4.5 directly without installing .NET 4.0 first. If the user doesn't have either, the application will tell him to install 4.0, which is not neccessary, but this is what the PE tells the loader. I don't think you can check for .NET 4.5 yourself in one turn without some sort of "bootstrapping". By that I mean writing a small program that checks the registry for the installed version and, if the correct version is installed, launches your actual program.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM