Question

I have a solution that contains several projects. One of the test projects is using .NET 4.0 due to a dependency. The deploy-able project I want to build is targeted against the .NET 3.5 compiler. Our current build script is not granular enough to target different .NET compilers on a project by project basis. Basically I can only use one compiler for every project in the solution.

Is the .NET 4.0 compiler smart enough to compile 3.5 code?

Solution Structure

  • Project 1 .NET 3.5 (deploy-able)
  • Project 2 .NET 4.0 (used for testing in automated build cycle)

Note: I can not just ignore Project 2, because our automated build server runs the unit tests in project 2. All tests must pass before a build is successful.

Edit:

I am not compiling this code within Visual Studio. We have a custom build script that is run external to visual studio. It is only smart enough to use 1 .NET compiler. It uses this compiler to compile all of the projects in a given solution. The build script does not care whether or not the projects are defined to be compiled against 3.5 or 4.0. Instead it compiles them with the defined compiler.

Project 1 does not reference project 2. Project 2 is a project containing unit tests. Our automated build tool compiles project 2 only to run tests.

Was it helpful?

Solution

EDIT

Op clarified the question is the comments as

Can the 4.0 compiler compile a 3.5 project

The answer is yes this is very possible.

OTHER TIPS

Right click on your "Project 1" project in the solution explorer. Next click Properties (hot key is ALT+Enter). Under the application tab there is a "Target Framework" drop down. Set that to 3.5.

Now when you compile (it sounds like you are using a command line) use MSBuild and don't specify a target framework version. Just compile the solution file and every project will compile properly.

You may run into issues depending on the types of libraries you are using. In particular I had trouble with namespaces/class names that didn't exist in in 3.5 that were implemented in 4.0.

If you are doing something esoteric like compiling NHibernate source code as part of your solution you will run into problems. Otherwise, if you aren't stepping on any namespaces you shouldn't have a problem compiling a 3.5 project to 4.0.

What is wrong with taking Bob's answer? Are you using a custom build solution (i.e. not Visual Studio)?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top