How to tell version of .NET used for a delivered project with no project or solution file?
I have a friend who was handed off a C#/.NET web project from a departed employee. The project had no project file or solution file, but did have the full contents of files, including code behind files.
We know that it was built using .NET 2.0 or higher because of some things found in the web.config file. But this raised the question:
If you don't have a project or solution file, or you run across a published codebase for a website,开发者_开发技巧 is there a utility or method that can be used to determine which version of the .NET framework is was built for? [We need the assumption that we can't look at IIS to see which version, in this case]
You can't reliably tell which version the code was written for, since (most) code written using only features of an earlier version compiles under newer versions. What you can do though is to try to build the project under different versions of the runtime, which is as close as you can get, I think.
Also, the whole .Net has quite good backwards-compatibility, so running under the newest version that's available for you would be my first try, and if the code run, I would stick with that.
If you have an assembly, you can check it's properties to see what framework it's targetting. That still won't tell you exactly what langauge version it was built using, but it will tell you the framework target.
With just the code, there is no way to know for certain. You can use C# 4 and target .NET 4, and write the exact same code as C# 2 targetting .NET 2, or C# 3 targetting .NET 3.5, provided you choose your classes carefully.
精彩评论