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.

Teena
  • 49
  • 1
  • 1
  • 2

5 Answers5

5

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

stuartd
  • 70,509
  • 14
  • 132
  • 163
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");
Thomas Levesque
  • 286,951
  • 70
  • 623
  • 758
  • We don't use project files, just use csc.exe to compile – Zoli Jun 13 '23 at 11:45
  • @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...) – Thomas Levesque Jun 13 '23 at 18:16
  • 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 – Zoli Jun 14 '23 at 15:16
  • 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...) – Thomas Levesque Jun 15 '23 at 12:52
  • Actually I like it, I know it inside-out (and no one else), but that's not related here... – Zoli Jun 16 '23 at 13:37
2
var document = XDocument.Load("ProjectName.csproj");
var targetFramework = document
    .Descendants(XName.Get("TargetFrameworkVersion", "http://schemas.microsoft.com/developer/msbuild/2003"))
    .First()
    .Value;
Alex Aza
  • 76,499
  • 26
  • 155
  • 134
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

Bhaumik Patel
  • 15,176
  • 5
  • 30
  • 33
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.

John Nicholas
  • 4,778
  • 4
  • 31
  • 50