<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>fooshen's : Visual Studio 2005</title><link>http://blogs.msdn.com/fooshen/archive/tags/Visual+Studio+2005/default.aspx</link><description>Tags: Visual Studio 2005</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Writing WSS2.0 WebParts using Visual Studio 2005</title><link>http://blogs.msdn.com/fooshen/archive/2006/11/27/writing-wss2-0-webparts-using-visual-studio-2005.aspx</link><pubDate>Mon, 27 Nov 2006 11:17:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1159852</guid><dc:creator>fooshen</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/fooshen/comments/1159852.aspx</comments><wfw:commentRss>http://blogs.msdn.com/fooshen/commentrss.aspx?PostID=1159852</wfw:commentRss><description>&lt;P&gt;Problem statement:&lt;/P&gt;
&lt;P&gt;Your corporate intranet portal/site is using Sharepoint Portal Server 2003 / Windows Sharepoint Services 2.0. You are mulling over whether to have Visual Studio .Net 2003 or the newer, cooler, and definately awesome Visual Studio 2005 as your corporate development tool of choice. You also want to make sure that you can develop webparts for&amp;nbsp;SPS 2003/WSS2.0 using the same IDE.&lt;/P&gt;
&lt;P&gt;Tough choice? It's really simple.&lt;/P&gt;
&lt;P&gt;Here's how:&lt;/P&gt;
&lt;P&gt;1.) Ditch Sharepoint Portal Server 2003. Upgrade to the latest, baddest kick-ass portal in town,&amp;nbsp;SharePoint Server 2007. Go with Visual Studio 2005, and you will attain unparalleled awesome-ness.&lt;/P&gt;
&lt;P&gt;2.) If you MUST develop for SharePoint Portal Server 2003 with Visual Studio 2005 - see #1 above.&lt;/P&gt;
&lt;P&gt;Ok, seriously. Building web parts for&amp;nbsp;SPS 2003/WSS2.0 using Visual Studio 2005, and you will undoubtedly venture into the problem area where you would want to use VS 2005 to build for .Net 1.1 runtime.&lt;/P&gt;&lt;BR&gt;&lt;STRONG&gt;MSBuild&lt;/STRONG&gt; 
&lt;P&gt;Enter &lt;A href="http://msdn2.microsoft.com/en-us/library/ms171452.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/ms171452.aspx"&gt;MSBuild&lt;/A&gt;,&amp;nbsp;the Microsoft Build Engine for Visual Studio / .Net platform. All it takes is some target specifications to direct MSBuild to build for .Net 1.1 runtime. Sounds easy? Not. &lt;/P&gt;&lt;BR&gt;&lt;STRONG&gt;MSBee&lt;/STRONG&gt; 
&lt;P mce_keep="true"&gt;Unless you have &lt;A href="http://www.microsoft.com/downloads/details.aspx?FamilyID=E0D0776F-25C4-444A-A6B9-71D06826F5B4&amp;amp;displaylang=en"&gt;MSBee&lt;/A&gt;, which will provide us some pre-defined target files to use with MSBuild. To install MSBee, make sure you have all the pre-requisites already installed (as noted in its download page). &lt;/P&gt;
&lt;P mce_keep="true"&gt;Now we are ready to&amp;nbsp;build a webpart&amp;nbsp;on .Net 1.1. Since we don't have any Web Part templates for SPS2003/WSS2.0 in Visual Studio 2005, we will start off with a plain old Class Library project. &lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://i88.photobucket.com/albums/k189/fooshen/sharepoint_vs2005_sps2003_001.jpg" border=0&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;First thing to do is to add a reference to Microsoft.Sharepoint.dll assembly from C:\Program Files\Common Files\Microsoft Shared\web server extensions\60\ISAPI\&lt;/P&gt;
&lt;P mce_keep="true"&gt;Add the "using" redirectives for Microsoft.Sharepoint, and remove the default System.Collections.Generic - we don't have generics in .Net 1.1.&lt;/P&gt;
&lt;P mce_keep="true"&gt;Example:&lt;/P&gt;
&lt;P mce_keep="true"&gt;using System;&lt;BR&gt;using System.Text;&lt;BR&gt;using Microsoft.SharePoint.WebPartPages;&lt;BR&gt;using System.Web.UI;&lt;BR&gt;using System.Web.UI.WebControls;&lt;BR&gt;using System.Reflection;&lt;/P&gt;
&lt;P mce_keep="true"&gt;namespace SharePoint2003WebPart&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public class MyWebPart: WebPart&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; protected override void CreateChildControls()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Label message = new Label();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; message.Text = "CLR Version: " + Assembly.GetExecutingAssembly().ImageRuntimeVersion;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; this.Controls.Add(message);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;}&lt;BR&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;Next, open the .csproj file, and add the following import statements into it:&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://i88.photobucket.com/albums/k189/fooshen/sharepoint_vs2005_sps2003_004.jpg" border=0&gt; &lt;/P&gt;
&lt;P&gt;Add a reference path to the project so that MSBuild can locate our Microsoft.SharePoint.dll assembly:&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://i88.photobucket.com/albums/k189/fooshen/sharepoint_vs2005_sps2003_005.jpg" border=0&gt;&lt;/P&gt;
&lt;P&gt;Provide a strong name key and we're ready. We have to sign it the old-fashioned VS.Net 2003 way - use "sn -k yourfile.snk" and adding the attribute [assembly: AssemblyKeyFile(../../yourfile.snk")] into AssemblyInfo.cs. &lt;/P&gt;
&lt;P mce_keep="true"&gt;Now we are ready to &lt;EM&gt;MSBee&lt;/EM&gt; it. From the Visual Studio command prompt, use the following command line:&lt;/P&gt;
&lt;P mce_keep="true"&gt;&lt;STRONG&gt;msbuild&lt;/STRONG&gt; &lt;EM&gt;{your csproj file}&lt;/EM&gt; &lt;STRONG&gt;/p:TargetFX1_1=true&lt;/STRONG&gt;&lt;/P&gt;&lt;IMG src="http://i88.photobucket.com/albums/k189/fooshen/sharepoint_vs2005_sps2003_006.jpg" border=0&gt; 
&lt;P mce_keep="true"&gt;Almost there now... Grab the assembly under the bin\FX1_1\debug (or release)&amp;nbsp;folder, (instead of \bin\debug)&amp;nbsp;and drop it into the Global Assembly Cache.&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;For SPS2003/WSS2.0 webparts, we need to&amp;nbsp;create&amp;nbsp;a corresponding .dwp file, contrasting to the self-reflected .webpart file in MOSS. In Visual Studio 2005, add a new xml file and name it&amp;nbsp;anything with .dwp extension. Get the PublicKeyToken value from the GAC, or use the -T command line switch with the Strong Name utility: sn -T &lt;EM&gt;assemblyName.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: maroon"&gt;?xml&lt;/SPAN&gt; version="1.0"?&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;BR&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: maroon"&gt;WebPart&lt;/SPAN&gt; xmlns="http://schemas.microsoft.com/WebPart/v2"&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: maroon"&gt;Assembly&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;AssemblyName(with no .dll extension),&amp;nbsp;Version=VersionNumber, Culture=Culture,&amp;nbsp;PublicKeyToken=PublicKeyToken&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: maroon"&gt;Assembly&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: maroon"&gt;TypeName&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;WebPartNamespace.WebPartClassName&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: maroon"&gt;TypeName&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: maroon"&gt;Title&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;DefaultWebPartTitle&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: maroon"&gt;Title&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: maroon"&gt;Description&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;WebPartDescription&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: maroon"&gt;Description&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&lt;BR&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN style="COLOR: maroon"&gt;WebPart&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;From SPS2003/WSS2.0 site, import the newly created dwp file, and we're done!&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://i88.photobucket.com/albums/k189/fooshen/sharepoint_vs2005_sps2003_007.jpg" border=0&gt; &lt;/P&gt;
&lt;P&gt;Can it be better? You bet. &lt;/P&gt;
&lt;P&gt;Right-click on your Visual Studio&amp;nbsp;2005 menu bar, and select Customize (waaay down below). On the Commands tab, select "Rearrange Commands". Select "Add" and choose "File" and then "Export Template" from the Commands selection.&lt;/P&gt;
&lt;P&gt;&lt;IMG src="http://i88.photobucket.com/albums/k189/fooshen/sharepoint_vs2005_sps2003_008.jpg" border=0&gt; &lt;/P&gt;
&lt;P&gt;When done, the new "Export Template" command will be available from the "File" menu. What this do is to take the existing SharePoint2003WebPart project and convert it into a Project template with all the project import targets and references intact, and the .dwp file is included as well. &lt;IMG src="http://i88.photobucket.com/albums/k189/fooshen/sharepoint_vs2005_sps2003_009.jpg" border=0&gt; &lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=1159852" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/fooshen/archive/tags/Visual+Studio+2005/default.aspx">Visual Studio 2005</category><category domain="http://blogs.msdn.com/fooshen/archive/tags/SharePoint+2003/default.aspx">SharePoint 2003</category></item></channel></rss>