SharePoint and Visual Studio - Replaceable parameters

Posted on 2/14/2012 @ 6:47 AM in #SharePoint by | Feedback | 4528 views

What is a replaceable parameter? Sometimes you may see something like $SharePoint.Project.AssemblyFullName$ in your code. Visual studio is doing some magic to replace it during compile/build time with the full assembly signature.

The following apply to these tokens or replaceable parameters -

  • Tokens can be specified anywhere in a line.
  • Tokens cannot span multiple lines.
  • The same token may be specified multiple times on the same line and in the same file.
  • Different tokens may be specified on the same line.
  • Tokens that do not follow these rules are ignored without providing a warning or error.
  • The replacement of tokens by string values is done immediately after manifest transformation, thus allowing manifest templates edited by a user to use tokens.

Visual studio supports the following replaceable parameters -

 

Name

Description

$SharePoint.Project.FileName$

The name of the containing project file, such as, "NewProj.csproj".

$SharePoint.Project.FileNameWithoutExtension$

The name of the containing project file without the file name extension. For example, "NewProj".

$SharePoint.Project.AssemblyFullName$

The display name (strong name) of the containing project’s output assembly.

$SharePoint.Project.AssemblyFileName$

The name of the containing project’s output assembly.

$SharePoint.Project.AssemblyFileNameWithoutExtension$

The name of the containing project’s output assembly, without the file name extension.

$SharePoint.Project.AssemblyPublicKeyToken$

The public key token of the containing project’s output assembly, converted to a string. (16-characters in "x2" hexadecimal format.)

$SharePoint.Package.Name$

The name of the containing package.

$SharePoint.Package.FileName$

The name of the containing package's definition file.

$SharePoint.Package.FileNameWithoutExtension$

The name (without extension) of the containing package's definition file.

$SharePoint.Package.Id$

The SharePoint ID for the containing package. If a feature is used in more than one package, then this value will change.

$SharePoint.Feature.FileName$

The name of the definition file of the containing feature, such as Feature1.feature.

$SharePoint.Feature.FileNameWithoutExtension$

The name of the feature definition file, without the file name extension.

$SharePoint.Feature.DeploymentPath$

The name of the folder that contains the feature in the package. This token equates to the "Deployment Path" property in the Feature Designer. An example value is, "Project1_Feature1".

$SharePoint.Feature.Id$

The SharePoint ID of the containing feature. This token, as with all feature-level tokens, can be used only by files included in a package via a feature, not added directly to a package outside of a feature.

$SharePoint.ProjectItem.Name$

The name of the project item (not its file name), as obtained from ISharePointProjectItem.Name.

$SharePoint.Type.<GUID>.AssemblyQualifiedName$

The assembly qualified name of the type matching the GUID of the token. The format of the GUID is lowercase and corresponds to the Guid.ToString("D") format (that is, xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).

$SharePoint.Type.<GUID>.FullName$

The full name of the type matching the GUID in the token. The format of the GUID is lowercase and corresponds to the Guid.ToString("D") format (that is, xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).

 

Also, by default, Visual Studio searches for tokens only in package files, manifest files, and files that have the following extensions:

  • XML

  • ASCX

  • ASPX

  • Webpart

  • DWP

These extensions are defined by the <TokenReplacementFileExtensions> element in the Microsoft.VisualStudio.SharePoint.targets file, located in the $ProgramFiles$\MSBuild\Microsoft\VisualStudio\v10.0\SharePointTools folder.

You can add to this list by adding an element like below,

<TokenReplacementFileExtensions>myextension;yourextension</TokenReplacementFileExtensions>
 

Sound off but keep it civil:

Older comments..


On 11/24/2012 3:47:55 PM Fred Morrison said ..
Practical example that I discovered after much pain and suffering after renaming several portions of a visual web part that was originally created with the Visual Studio 2012 Visual Web Part creation wizard that I eventually traced to Visual Studio 2012's extremely poor (incomplete) Rename command, which failed to find and replace all occurrences of the things I was renamings:


(1) click "Show All Files" icon within Solution Explorer


(2) location the .spdata file and open it up.


In my case, the SafeControl was wrong (victim of the previously mentioned bug in Visual Studio 2012's Rename command) which I changed as follows (hard-coded one is commented, token replacement edition is active:


<!--<SafeControl Name="SafeControlEntry1"


Assembly="$SharePoint.Project.AssemblyFullName$"


Namespace="VisualHelloWorld.VisualHelloWorldWebPart"


TypeName="*"


IsSafe="true"


IsSafeAgainstScript="false" />-->


<SafeControl Name="SafeControlEntry1"


Assembly="$SharePoint.Project.AssemblyFullName$"


Namespace="$SharePoint.Project.AssemblyFileNameWithoutExtension$.VisualHelloWorldWebPart"


TypeName="*"


IsSafe="true"


IsSafeAgainstScript="false" />