How to get the package name or other names of SharePoint items (Phil Hoff)

You can use replaceable parameters inside project files to provide values, such as SharePoint project file names, assembly names, package names, feature names, and more. The full list of replaceable parameters is documented at Replaceable Parameters.

Here is a code example of how to use the replaceable parameter for a SharePoint package name in a VSIX extension.

// Get the DTE project you’re interested in.
EnvDTE.Project dteProject = …

// Get a service provider from somewhere.
IServiceProvider serviceProvider = …

// Get the SharePoint project service (our extensibility API—reference Microsoft.VisualStudio.SharePoint.dll).
var projectService = serviceProvider.GetService(typeof(ISharePointProjectService)) as ISharePointProjectService;

// Convert the DTE project into the corresponding SharePoint project.
var project = projectService.Convert<EnvDTE.Project, ISharePointProject>(project);

// Get the package name from the package file’s (i.e. *.package) object model.
string packageName  = project.Package.Model.Name;

Comments (0)