0

I have recently found out that (merely) installing Visual Studio 2012 on my machine, causes Visual Studio 2010 to use the newer C# compiler. This happens even when setting the language version to 4 (http://ericlippert.com/2013/04/04/what-does-the-langversion-switch-do/).

I wanted to know if it were possible to force Visual Studio to use the old compiler anyway. I think it's not possible because it seems that the compiler is installed in the framework folder which is the same for .NET 4 and .NET 4.5, but I was wondering if someone managed to do it anyway somehow.

Dina
  • 1,346
  • 1
  • 15
  • 35
  • 5
    Can I ask why you want that? – Christoph Fink Apr 24 '14 at 11:33
  • 2
    You don't have the "old" compiler anymore, it was replaced when the VS2012 installer installed .NET 4.5 on your machine. The entire .NET 4.0 install is gone, replaced as well. So no, not an option. – Hans Passant Apr 24 '14 at 12:06
  • @chrfin I want this because I have an inconsistent build environment and executables behave differently depending on where they were compiled. Some of my products need .NET 4.5 and C# 5 and some don't. I want to control the compiler for each product. – Dina Apr 24 '14 at 12:41
  • The set up different build machines with the appropriate environments installed. Thats how we do it here. Or is it already a problem during development? – Christoph Fink Apr 24 '14 at 12:56
  • @chrfin This is indeed an option and that's what we're going to do if there's no other choice. But we have many projects with different environments and it would be easier not to have to maintain different sets of build machines. – Dina Apr 24 '14 at 13:02

2 Answers2

0

You can use the command line compiler see here, and run your code on the old compiler in post build actions

Community
  • 1
  • 1
Shachaf.Gortler
  • 5,655
  • 14
  • 43
  • 71
  • 1
    But the compiler is installed in the framework folder and if my computer has .NET 4.5 or 4.5.1 then it will have a new version of the compiler. Is it possible to install 4.5 and 4.5.1 not in place of the 4.0? – Dina Apr 24 '14 at 12:45
0

As I said in my original question and as some commented, it indeed seems this would be impossible. The new compiler is installed in the same place as the old compiler. One would need to have a clean build environment with the exact compiler needed.

Dina
  • 1,346
  • 1
  • 15
  • 35