简体   繁体   中英

Different Target .Net Framework on each C# Project

is it ok if i have this X project using .net2.0, and that X project is calling Y project which is using .net3.5.. i got customized buttons in Y project and im using that button in X project also, there's a method in Y project that has LINQ and X project is calling that method... i cant test it because i installed the latest .net framework.. :)

this is my code in project that has the .net3.5

    [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
    public static extern int GetDriveType(string lpRootPathName);        

    public enum DriveType : int
    {
        Unknown = 0,
        NoRoot = 1,
        Removable = 2,
        Localdisk = 3,
        Network = 4,
        CD = 5,
        RAMDrive = 6
    }
    var selectedDrives = from s in Environment.GetLogicalDrives() where Enum.GetName(typeof(DriveType), GetDriveType(s)).Equals(DriveType.Removable) select s;
        foreach (String drives in selectedDrives)
        {
            MessageBox.Show(drives);

        }

correct also the LINQ statement if i did it wrong.. :)

If the 3.5 framework is not installed on the machine that executes this, it will fail as System.Linq.dll won't exist. You can use LINQBridge with .NET 2.0 and C# 3.0 (which will give you access to a re-implementation of LINQ-to-Objects) but in reality it may be easier to get the client to upgrade. 2.0 is pretty old now.

Alternatively... if all you need is a where , there are easier routes. For example:

foreach (String drives in Environment.GetLogicalDrives())
{
    if(!Enum.GetName(typeof(DriveType), GetDriveType(s))
        .Equals(DriveType.Removable))
    {
        continue;
    }
    MessageBox.Show(drives);
}

A .NET 2.0 project cannot call a method in a .NET 3.5 project.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM