none
VS2008 different target frameworks in one solution RRS feed

  • General discussion

  • I have the following projects in a VS2008 solution (simplified):
    - Project Sub, target framework .NET 2.0
    - Project Main, references Project Sub, target framework .NET 3.5

    Now the "exciting" part: by accident I used .NET 3.5 code inside project Sub. Despite having set the target framework to .NET 2.0 the project compiles without any error and even works without any error. BTW, what I used in project Sub was the following line of code

    List<string> someList = new List<string>{"A", "B", "C"};
    My question: is setting the target framework only usefull for the startup project (Main)? I was hoping project Sub would be validated against the .NET 2.0 framework. Since this does not seem to be the case I can see some problems arising when project Sub is used again in another project that is entirely .NET 2.0.
    • Changed type YiChun Chen Friday, May 15, 2009 2:18 AM Do not follow up
    Friday, May 8, 2009 8:43 AM

All replies

  • Hi,
      TO use teh above code you only need framework 2.0 i think. Because i am using it. You are not using any thing which is in 3.0+ and is not in 2.0. The generics which you are using is a part of C# 2 and is available in framework 2. It maybe of some other issue. There wont be any error because of the above line of cod you mentioned. Please observe it carefully and find out the reason. 

    -- Thanks Ajith R [Mark as Answer if it is Helpful.]
    Friday, May 8, 2009 8:51 AM
  • When I use the same code in VS2005 it gives me an error and have to recode it to C# 2 compliant code:

    List<string> someList = new List<string>();
    someList.Add("A");
    someList.Add("B");
    someList.Add("C");

    However, with C# 3 (and .NET 3.x?) it is possible to use my previous code. The thing you could do in C# 2 was:

    string[] someArray = new string[]{"A", "B", "C"};

    But that is an array variable, not a generic collection.
    Friday, May 8, 2009 9:06 AM
  • Hi Paul van de Sande,

    Could you please help me to clarify your issue more? What do you mean "project Sub is used again in another project that is entirely .NET 2.0"? What kind of prject does "project Sub"? A class or others?

    The project that are complied on 3.5 can be run on the machine that has 2.0.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Monday, May 11, 2009 9:53 AM
  • Hi Paul van de Sande,

    We are changing the issue type to “Comment” because you have not followed up with the necessary information. If you have more time to look at the issue and provide more information, please feel free to change the issue type back to “Question” by editing your initial post and changing the radio button at the top of the post editor window. If the issue is resolved, we will appreciate it if you can share the solution so that the answer can be found and used by other community members having similar questions.

    Thank you!
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Friday, May 15, 2009 2:17 AM
  • Apologies for my late reaction. Holiday and all that ...

    I will try to explain a bit further:

    Solution 1 in VS2008 contains:
    - Project Main1, which is a .NET 3.5 project and has a reference to Project Sub
    - Project Sub, which is a .NET 2.0 project

    Solution 2 in VS2005 contains:
    - Project Main2, which is a .NET 2.0 project and has a reference to Project Sub
    - Project Sub, which is exactly the same project as in solution 1 and a .NET 2.0 project

    It does not matter really what each project contains, classes, forms or otherwise.

    Now, add the following line of code to project Sub in solution 1:
    List<string> someList = new List<string>{"A", "B", "C"};

    Try to compile solution 2 with the changed project Sub and you will get an error. Do the same with solution 1 and it compiles without a hitch. This seemed very odd to me, because project Sub is a .NET 2.0 project in both cases and compiling them in both solutions should give the same result.

    Although I still have to test this I think I know where my reasoning went wrong: the line of code is valid in C#3.0 and not in C#2.0. Not everything you can do in C#3.0 works under the .NET 2.0 framework, however: a lot of things do. This was one of them. The webpage that set me on the right path was this one:
    http://www.danielmoth.com/Blog/2007/05/using-c-30-from-net-20.html

    Simplified: I thought C#3.0 = .NET 3.5 and C#2.0 = .NET 2.0 framework, which is obviously not the case.

    One last thing: Yichun Chen, you said the following "The project that are complied on 3.5 can be run on the machine that has 2.0". Maybe I am reading this the wrong way, but are you saying that a project compiled againt the .NET 3.5 framework can run on a machine that only has the .NET 2.0 framework installed? That can't be right can it?

    BTW: I cannot change the issue type back to "Question", because I seem to be missing the radio button you are referring to. However, changing it is not really needed anymore I guess.

    Tuesday, May 26, 2009 8:01 AM