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)
我需要引用两个不同版本的Sharepoint API dll。我有一个需要在Sharepoint 2和Sharepoint 3下运行的web服务,但还需要使用Sharepoint 3 API提供的新功能(Checkout和内容审批)
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
2 个解决方案
#1
3
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.
这就是我如何吐出针对WSSv2 API和针对WSSv3程序集编译的.NET 2.0编译的.NET 1.1版本。它适用于VS 2005和2008。
You will need to use MSBEE http://www.codeplex.com/Wiki/View.aspx?ProjectName=MSBee
您需要使用MSBEE http://www.codeplex.com/Wiki/View.aspx?ProjectName=MSBee
Working with .NET 1.1 with Visual Studio 2008
与Visual Studio 2008一起使用.NET 1.1
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)
打开* .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>
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
如果您遇到编译器错误但代码看起来正确,则可能是该错误仅适用于.NET1.1 / WSSv2并且在.NET2 / WSSv3中编译良好。检查输出选项卡以查看发生错误的目标
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.
您还需要掌握一些MSBUILD忍者动作以保持一步构建过程并保持自己的健康http://brennan.offwhite.net/blog/2006/11/30/7-steps-to-msbuild/使用MSBUILD你可以让VS同时编译两个版本而无需使用命令行。
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.
这将在.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>
#2
2
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
.
这是VB后期绑定(选项严格关闭)方法运行良好的时候之一。滚动C#4.0并动态。
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)
您可以尝试为所需的位编写接口(在基础库中),并编写2个dll:一个引用sharepoint dll的每个版本。对于这两个项目,实现接口(对于您不能执行的操作抛出NotSupportedException),并在运行时加载相应的dll? (工厂方法)
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.
在你过于专注之前,只需用一种方法尝试它......除非你知道它适用于最简单的方法,否则不要做整件事。
#1
3
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.
这就是我如何吐出针对WSSv2 API和针对WSSv3程序集编译的.NET 2.0编译的.NET 1.1版本。它适用于VS 2005和2008。
You will need to use MSBEE http://www.codeplex.com/Wiki/View.aspx?ProjectName=MSBee
您需要使用MSBEE http://www.codeplex.com/Wiki/View.aspx?ProjectName=MSBee
Working with .NET 1.1 with Visual Studio 2008
与Visual Studio 2008一起使用.NET 1.1
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)
打开* .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>
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
如果您遇到编译器错误但代码看起来正确,则可能是该错误仅适用于.NET1.1 / WSSv2并且在.NET2 / WSSv3中编译良好。检查输出选项卡以查看发生错误的目标
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.
您还需要掌握一些MSBUILD忍者动作以保持一步构建过程并保持自己的健康http://brennan.offwhite.net/blog/2006/11/30/7-steps-to-msbuild/使用MSBUILD你可以让VS同时编译两个版本而无需使用命令行。
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.
这将在.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>
#2
2
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
.
这是VB后期绑定(选项严格关闭)方法运行良好的时候之一。滚动C#4.0并动态。
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)
您可以尝试为所需的位编写接口(在基础库中),并编写2个dll:一个引用sharepoint dll的每个版本。对于这两个项目,实现接口(对于您不能执行的操作抛出NotSupportedException),并在运行时加载相应的dll? (工厂方法)
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.
在你过于专注之前,只需用一种方法尝试它......除非你知道它适用于最简单的方法,否则不要做整件事。