Replacement Tokens for VS2010 and SharePoint Projects


In a recent project, I needed to create an handler that returns an RSS feed for a custom web part. I added a new text file with the appropriate file extension and set the contents of the file to:

<%@ Assembly Name=&quot;Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c&quot; %>
<%@ Assembly Name=&quot;$SharePoint.Project.AssemblyFullName$&quot; %>
<%@ WebHandler Class=&quot;IdeaCenterWebParts.Code.SiteActivityRSSHandler&quot; %>

After compiling and deploying the project to SharePoint, each time I accessed the handler I received an error about an assembly not being found. To avoid delaying the project, I simply provided the full assembly name (IdeaCenterWebParts, Version=, Culture=neutral, PublicKeyToken=5e88564ecf55ef51) and went about my business.

I received some requests to change the project and to try to avoid versioning conflicts I updated my file version from to and then my error returned. This lead me down a path of discovery.


One of the nice things about developing in Visual Studio for SharePoint 2010 projects are replacement tokens provided in the project. First, tokens are replaced at the end of the packaging of the solution so it will only work with non-compiled files. This is great for features and other code depending on these tokens to be dynamically created. However, there are only a handful of files where tokens are searched and replaced. The default list includes many of the common ones that you would typically use in a project:

  • XML
  • ASCX
  • ASPX
  • Webpart
  • DWP

Notice, WCF Services Files (SVC), ASP.NET Handler Files (ASHX) and ASP.NET SOAP Web Services are not included in the list. This means the files will be ignored and the token will remain. I figured there has to be a way to resolve this so I read on further in the article on MSDN. According to this article, the simple way to fix the problem is to open the project file (.csproj/.vbproj) and edit the XML to include your additional targets. This is done on a project by project basis.

Simply add a line similar to the following to the first PropertyGroup:


Here’s my project’s first PropertyGroup node:

    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>

Now, if I change the version number or assembly name of the project my references stay up-to-date!