如何引用一个API的两个版本? [英] How to reference two versions of an API?

查看:187
本文介绍了如何引用一个API的两个版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个需要参考两个不同版本在SharePoint API的dll。我有一个需要在两者的Sharepoint 2和Sharepoint 3上运行一个Web服务,而且还需要与由SharePoint 3 API(结帐和内容审批)

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

什么是达致这最好的方式 - 我目前倾向于有两个项目,这两个在​​使用条件编译编译代码的各个部分之间共享一个单一的文件中的代码

What is the best way to acheive this - I'm currently leaning towards having two projects, with the code in a single file shared between the two with various sections of the code compiled in using conditional compilation.

有没有更好的办法?

感谢

推荐答案

这是我怎么吐出反对WSSv2 API编写.NET 1.1版本和.NET 2.0对WSSv3组装编译。它将为2005和VS 2008年的工作。

This is how I spit out .NET 1.1 versions compiled against WSSv2 API and .NET 2.0 compiled against WSSv3 assembly. It will work for VS 2005 and 2008.

您将需要使用MSBEE的 http://www.codeplex.com/Wiki/View.aspx?ProjectName=MSBee

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

< A HREF =htt​​p://devlicio.us/blogs/ziemowit_skowronski/archive/2008/08/22/working-with-net-1-1-in-visual-studio-2008-and-team-server.aspx相对=nofollow>与.NET 1.1的工作与Visual Studio 2008

打开*的.csproj,并找出在SharePoint DLL被引用和改变这样的事情在哪你的目标改变引用的程序集视(FX1_1意味着你的目标.NET1.1,因此WSSv2)

Open up *.csproj and find out where the SharePoint dll is referenced and change to something like this which changes the referenced assembly depending upon your target (FX1_1 means 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 where necessary

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

如果你得到一个编译器错误,但代码看起来正确也可能是错误仅.NET1.1 / WSSv2和编译罚款.NET2 / WSSv3。检查输出标签来查看哪些目标发生错误

If you get a compiler error but the code looks right it may be that the error is only for .NET1.1 / WSSv2 and compiles fine in .NET2/WSSv3. Check the output tab to see for which target the error occurred

您还需要掌握一些MSBUILD忍者动作保持1步构建过程,并保持自己清醒的 http://brennan.offwhite.net/blog/2006/三十零分之十一/ 7步到的MSBuild / 使用MSBUILD你可以得到VS编译两个版本在同一时间,而不诉诸命令行。

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

.NET已完成,输出一些信息到输出窗口,以帮助您找出发生错误的所在后,这将运行.NET1.1编译。

This will run the .NET1.1 compilation after .NET has finished and output some messages to the Output window to help you work out where 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>

这篇关于如何引用一个API的两个版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆