如何引用一个API的两个版本?

发布于 2024-07-08 03:55:26 字数 248 浏览 10 评论 0原文

我需要引用两个不同版本的 Sharepoint API dll。 我有一个 Web 服务需要在 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.

Is there a better way ?

Thanks

Matt

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

玩心态 2024-07-15 03:55:26

这就是我如何吐出针对 WSSv2 API 编译的 .NET 1.1 版本和针对 WSSv3 程序集编译的 .NET 2.0 版本。 它适用于 VS 2005 和 2008。

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

在 Visual Studio 2008 中使用 .NET 1.1

一些提示

打开 *.csproj 并查找找出引用 SharePoint dll 的位置,并更改为类似的内容,这会根据您的目标更改引用的程序集(FX1_1 表示您的目标是 .NET1.1,因此是 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>

如有必要,请使用条件编译来解决差异

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

如果您收到编译器错误,但代码看起来正确,可能该错误仅适用于 .NET1.1 / WSSv2,并且在 .NET2/WSSv3 中可以正常编译。 检查输出选项卡以查看哪个目标发生了错误

您还需要掌握一些 MSBUILD 忍者动作,以保持一步构建过程并保持理智http://brennan.offwhite.net/blog/2006/11/30/7-steps-to-msbuild/ 使用MSBUILD,你可以让VS同时编译两个版本,而无需求助于命令行。

这将在 .NET 完成后运行 .NET1.1 编译,并向“输出”窗口输出一些消息,以帮助您找出发生错误的位置。

<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>

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.

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

Working with .NET 1.1 with Visual Studio 2008

Some tips

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

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

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.

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>
秋日私语 2024-07-15 03:55:26

您可以尝试使用“外部别名”。

这是 VB 后期绑定(选项严格关闭)方法效果很好的时候之一。 继续使用 C# 4.0 和动态

您可以尝试为您需要的位(在基础库中)编写一个接口,并编写 2 个 dll:一个引用每个版本的 sharepoint dll。 对于这两个项目,实现接口(对于无法执行的部分抛出 NotSupportedException),并在运行时加载适当的 dll? (工厂方法)

在您过于专注之前先尝试使用单一方法...直到您知道它适用于最简单的简单方法之前,不要做整个事情。

You could give an "extern alias" a go.

This is one of those times when the VB late binding (option strict off) approach works well. Roll on C# 4.0 and dynamic.

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

Just try it with a single method before you get too absorbed... don't do the whole thing until you know it works for the simplest of simple methods.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文