Visual Studio implementation to write a set of. NET code, simultaneously compiled to multiple platforms, multi-version operation notes

Source: Internet
Author: User

Title, put a set of code. NET code. Compiled into multi-platform, multi-version DLL files,

Project structure (CVS file read/write open source Component Https://github.com/JoshClose/CsvHelper)

Such as. The project Engineering Csvhelper is the main project of the class library.

CsvHelper20,CsvHelper35,csvhelperpcl are different. NET version corresponds to project engineering,

Class Library Project Engineering,CsvHelper20,CsvHelper35,csvhelperpcl using the Cvshelper code file (directly by adding the Project link file + Conditional compilation symbols ).

Let's do it by myself again. I feel confused by what I say in the clouds. O (︶^︶) o ~

First step (0x01), create Project Engineering:

5 new project projects, such as,

Oceanho.common (engineering code is written in this project,. NET version 4.0)

OCEANHO.COMMONNET20 (Oceanho.common for. NET2.0 version,. NET version 2.0)

OCEANHO.COMMONNET20 (Oceanho.common for. NET4.0 version,. NET version 4.0)

OceanHo.Common.ExampleDo (the code for the test project is written here,. NET version 4.0, need to reference Oceanho.common)

OCEANHO.COMMON.EXAMPLEDONET20 (the code for the test project is written here,. NET version 2.0, need to reference oceanho.commonnet20)

OCEANHO.COMMON.EXAMPLEDONET40 (the code for the test project is written here,. NET version 4.0, need to reference OCEANHO.COMMONNET40)

Second step (0x02), add conditional compilation symbols:

Set The conditional compilation symbol for the project oceanho.commonnet20 to the NET20,OCEANHO.COMMONNET40 conditional compiler character number to NET40

Note: net20 and NET40 are custom, not must call this name ha, set complete, such as.

Step Three (0x03), new CSharp source file:

Add the ObjectExtension.cs code to the Oceanho.common (no hurry, the last side of the code will be dropped on GitHub)

Fourth step (0x04), add source code file Link:

Add Oceanho.common to OCEANHO.COMMONNET20,OCEANHO.COMMONNET40 two projects

Properties\assemblyinfo.cs

ObjectExtension.cs

Two file link references, action ( check oceanho.commonnet20, right mouse-"add-" Existing Item )

When the operation is complete, you will see as shown.

Oh, to the bird, ~ ~ ~ OCEANHO.COMMONNET40 Project also the same as the method of operation. O (∩_∩) o ~

Fifth Step (0x05), let. NET 2.0 support static method extensions:

Add ExtensionAttribute.cs to Oceanho.commonnet20

1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Text;4 5 /** * * * here namespace *************/6 namespaceSystem.Runtime.CompilerServices7 {8     /// <summary>9     ///a support tag class that defines an extension method for. NET 2.0 can support static method extensions without referencing upgrade. NET to 3.5 and referencing. NET 3.5 assembliesTen     /// </summary> One[AttributeUsage (attributetargets.assembly | AttributeTargets.Class |AttributeTargets.Method)] A      Public Sealed classExtensionattribute:attribute -     { -     } the}

Sixth step (0x06), write a console test program to see the effect:

Seventh Step (0x07), look at the Add File link OceanHo.CommonNET20.csproj:

You can see that, in fact, the Added link code file is under the Compile node plus a link node linked to this project.

Code for the convenience of their own to continue to learn, has been put on GitHub.

Https://github.com/oceanho/OceanHo.MultiVerCompileTests

Visual Studio implementation to write a set of. NET code, simultaneously compiled to multiple platforms, multi-version operation notes

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.