How to reference two API versions?

I need to reference two different versions of the Sharepoint API dll. I have a web service that needs to be launched using both Sharepoint 2 and Sharepoint 3, but I also need to work with the new features provided by the Sharepoint 3 API (Checkout and Content Approval).

What is the best way to achieve this - I am currently inclined towards two projects: code in a single file shared between them, with different sections of code compiled using conditional compilation.

Is there a better way?

thanks

Matt

+7
reference c # sharepoint sharepoint-api
source share
2 answers

This is how I spat out the versions of .NET 1.1 compiled against the WSSv2 API and .NET 2.0 compiled against the WSSv3 build. He will work in VS 2005 and 2008.

You will need to use MSBEE http://www.codeplex.com/Wiki/View.aspx?ProjectName=MSBee

Work with .NET 1.1 with Visual Studio 2008

Some tips

Open the * .csproj file and find out where the link to the SharePoint dll is referenced, and change something similar that will change the link assembly depending on your purpose (FX1_1 means that you are targeting .NET1.1 and therefore WSSv2)

<Reference Include="Microsoft.SharePoint"> <HintPath Condition="'$(TargetFX1_1)'!='true'">pathto\WSS3\Microsoft.SharePoint.dll</HintPath> <HintPath Condition="'$(TargetFX1_1)'=='true'">pathto\WSS2\Microsoft.SharePoint.dll</HintPath> </Reference> 

Use conditional compilation for differences if necessary

 #if FX1_1 // WSSv2 specific code #else // WSSv3 specific code #endif 

If you get a compiler error, but the code looks correct, it may happen that the error is only for .NET1.1 / WSSv2 and compiles to .NET2 / WSSv3. Check the output tab to see for what purpose the error occurred.

You will also need to master some of the MSBUILD ninja moves in order to preserve the 1 step creation process and keep yourself in order http://brennan.offwhite.net/blog/2006/11/30/7-steps-to-msbuild/ using MSBUILD. can force VS to compile both versions at the same time without resorting to the command line.

This will start compiling .NET1.1 after .NET shuts down and displays some messages in the output window to help you figure out where the errors occurred.

 <Target Name="BeforeBuild"> <Message Text="--- Building for .NET 1.1 ---" Importance="high" Condition="'$(TargetFX1_1)'=='true'" /> <Message Text="--- Building for .NET 2.0 ---" Importance="high" Condition="'$(TargetFX1_1)'!='true'" /> </Target> <Target Name="AfterBuild" Condition="'$(TargetFX1_1)'!='true'"> <MSBuild Projects="$(MSBuildProjectFile)" Properties="TargetFX1_1=true;" /> </Target> 
+3
source share

You can give "extern alias" go.

This is one of those cases where the VB late binding approach (strict off option) works well. Go to C # 4.0 and dynamic .

You can try to write an interface for the bits you need (in the base library) and write 2 dlls: one that links to each version of the sharepoint dll. For both projects, implement an interface (throwing a NotSupportedException for bits you cannot do) and load the appropriate dll at runtime? (factory approach)

Just try with one method before you get too absorbed ... don't do all this until you find out that it works for the simplest simple methods.

+2
source share

All Articles