R – .Net multitargeting gone wrong

.net-2.0multitargetingvisual-studio-2008

I have a small dummy project in VS 2008, contains only the following code file

using System;

namespace FrameworkTest
{
    internal static class MessageQueueNative
    {
        struct TestStructure
        {
            public IntPtr aStatus;
        }

        public static void Main()
        {
            TestStructure pMgmtProps = new TestStructure { aStatus = IntPtr.Zero };
        }
    }
}

The project is set to target framework 2.0, even set the ToolsVersion to 2.0 manually in the project. Now the project is building just fine from VS and fails from command line (using csc.exe 2.0).

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Csc.exe /noconfig /nowarn:1701,1702 /errorreport:prompt /warn:4 /define:DEBUG;TRACE /reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Data.dll /reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.dll /reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Xml.dll /debug+ /debug:full /filealign:512 /optimize- /out:obj\Debug\FrameworksTest.exe /target:exe Class1.cs Properties\AssemblyInfo.cs

Now the question is why does it compile from VS? It should fail as it does in case of cmd line compile.
The same source fails (correctly) in VS2005 project.

Thanks,
florin

Best Answer

Multitargeting means CLR-version-targeting, not C#-version-targeting.