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

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

问题描述

我需要引用两个不同版本的 Sharepoint API dll.我有一个需要在 Sharepoint 2 和 Sharepoint 3 下运行的网络服务,但还需要使用 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 版本和针对 WSSv3 程序集编译的 .NET 2.0 版本.它适用于 VS 2005 和 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

使用 .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'">pathtoWSS3Microsoft.SharePoint.dll</HintPath>
  <HintPath Condition="'$(TargetFX1_1)'=='true'">pathtoWSS2Microsoft.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/11/30/7-steps-to-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天全站免登陆