4

I am working on scanner kind of application which takes different C# codebases as input.I want to know in which .net framework version(1.1/2.0/3.5/4.0) specific codebase is built.

Can anybody provide me code to check .net framework version of codebases? can i read codebase version from .csproj file ? If yes, please provide code for same.

Thanks,

Teena.

1
  • ildasm YourAssembly.dll /text | grep "Metadata version:" Commented Jun 14, 2011 at 10:05

5 Answers 5

5

Look for the TargetFrameworkVersion and RequiredTargetFramework attributes in the .csproj file: there's code here to open and parse the project file.

Sign up to request clarification or add additional context in comments.

4 Comments

We don't use project files, just use csc.exe to compile
@Zoli well this answer is twelve years old..
No problem, but the original problem/question is still valid
So I suppose you want to work out which version of csc.exe to use? If though you don't have projects, though, then the Net Framework version isn't defined anywhere..
2

Can anybody provide me code to check .net framework version of codebases? can i read codebase version from .csproj file ?

Use the Project class:

string projectFileName = ...
Project proj = new Project(projectFileName);
string version = proj.GetPropertyValue("TargetFrameworkVersion");

5 Comments

We don't use project files, just use csc.exe to compile
@Zoli don't. You're only making things harder for yourself. There's a whole SDK to build .NET applications, csc.exe being one of the lowest level tools of that SDK. You're not supposed to use csc.exe directly. This isn't 2002 (and even then you usually didn't need to use it directly...)
it's not an option, big multiplatform / multilanguage project, most of the do not even have projects files at all, everything is compiled by cl.exe / csc.exe / midl.exe / rc.exe / etc - by jam
Ouch, good luck with that. Sounds like a nightmare. Honestly, if I had to maintain an app like that, I would probably quit on the spot. (sorry, I realize that's not very helpful...)
Actually I like it, I know it inside-out (and no one else), but that's not related here...
2
var document = XDocument.Load("ProjectName.csproj");
var targetFramework = document
    .Descendants(XName.Get("TargetFrameworkVersion", "http://schemas.microsoft.com/developer/msbuild/2003"))
    .First()
    .Value;

Comments

0

the cs proj file is an xml document

just open it and have a look you can parse it and work with it like any xml document.

1 Comment

We don't use project files, just use csc.exe to compile
0

steps for windows application:

1) Right click on project that you want to know framework version.

2) Click on “Properties” or press “ALT+ENTER”.

3) Now click on “Compile” tab from tree view.

4) Click on “Advance Compile Options..” appear at bottom.

5) It opens Settings pop up and from that you can find out “Target Framework”. From that you can also change framework of your application and save settings. That’s it.

You can also refer following image for faster review:

enter image description here

enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.