Condividi tramite


Multi-Targeting and N-Tier Dataset

Multi-Targeting in Visual Studio

What is Multi-Targeting in Visual Studio?

The multi-targeting feature of Visual Studio lets you specify the version of the .NET Framework, or its profile, that is required for your application.

For example, with Multi-Targeting, you can use the latest Visual Studio to continue to develop your existing projects that were created in Visual Studio 2008 or even earlier without adding new .NET Framework dependencies. The key benefit is you can leverage those new features/tools in the latest release of Visual Studio.

In Visual Studio 2008, we've already had some support for Multi-Targeting -- you can create and develop projects targeting to .NET 2.0, 3.0 and 3.5. All these framework versions still use the same common language runtime (CLR) 2.0 so it’s easier for Visual Studio to switch targets.

However, in Visual Studio 2010, it is much more complicated than before. For example, we have different .NET framework versions (2.0, 3.0, 3.5 and 4.0); we have different profiles (Client Profile vs. Full Profile); we have different .NET runtime versions (2.0 vs. 4.0); we have different frameworks (.NET framework vs. Silverlight framework). The good news is that Visual Studio 2010 will be fully supporting Multi-Targeting. You can use it to create and develop projects targeting any configuration.

If you'd like to learn more about Multi-Targeting, here is the walkthrough for Visual Studio 2010 beta 1.

https://msdn.microsoft.com/en-us/library/bb398202(VS.100).aspx

If you are also interested in other features in Visual Studio 2010 beta 1, here is the complete walkthroughs,

https://msdn.microsoft.com/en-us/vstudio/dd441784.aspx

You can download and try Visual Studio 2010 beta 1 here.

https://msdn.microsoft.com/en-us/vstudio/dd582936.aspx

N-Tier Dataset

Now, let's talk about Dataset Designer -- one of the frequently used data related features in Visual Studio. Some of you may already know that Dataset Designer supports N-Tier applications by splitting Datasets and TableAdapters into different projects. This is usually called N-Tier Dataset. If you are unfamiliar with this feature, please see this How Do I video. This means that you can now physically separate the data access layer (the tableAdapters) from your entities (the dataset structure and validation code). This allows you to share just the entities on the client-side leaving the data access layer on the server side giving you clean n-tier separation.

In Visual Studio 2010, we have the complicated Multi-Targeting scenarios, so what is the impact on the N-Tier Dataset?

An example of a N-Tier DataSet application is shown as below. The dataset project item is in the TableAdapter project, which is the data access layer. The dataset classes will be generated in the DataSet project, which is the data structure layer.

image

In Visual Studio 2008, when you want to split the DataSet from the TableAdapters, the .NET framework version of the target DataSet project must be equal or greater to the TableAdapter project. Because we need to make sure the Datasets are working correctly in the target project. However, you may find that this is not true in Visual Studio 2010. Because with the new CLR 4.0, if the TableAdapter project is targeting the .NET framework 3.5 (CLR 2.0), it cannot reference a DataSet project which targets the .NET framework 4.0 (CLR 4.0).

So in Visual Studio 2010, the requirement will be -- The dataset project must be targeting to the same version of the .NET framework as the TableAdapter project.

There is also another interesting scenario I'd like to mention here. For instance, say you have a Visual Studio 2008 solution with two projects as an N-Tier Dataset application and both of these two projects are targeting the .NET framework 3.5. (figure below)

image

Now you want to use Visual Studio 2010 for development and you want to re-target both of your projects to the .NET framework 4.0. So you reset the target framework version of TableAdapter project, then you may see an error about the MSDataCodeGenerator custom tool.

image

This is because at this time, you have one project re-targeted 4.0, but the other one is still 3.5.  You can ignore this error and continue to re-target the other project. After you finish, you can re-run the MSDataSetCodeGenerator custom tool by right-clicking the dataset project item and then click [Run Custom Tool]. It will regenerate Dataset classes in the target project, and you are good now!

image

 

Cheers!