private Dictionary <string, string> GetSharePointFileTokenReplacements(ISharePointProject project) { if (!this.ProjectTokenReplacements.ContainsKey(project.Id)) { var assemblyName = AssemblyName.GetAssemblyName(project.OutputFullPath); if (assemblyName == null) { this.ProjectService.Logger.ActivateOutputWindow(); this.ProjectService.Logger.WriteLine($"Please build the project {project.FullPath} at least one time to create the replace tokens.", LogCategory.Warning); return(new Dictionary <string, string>()); } var tokens = new Dictionary <string, string> { { "$SharePoint.Project.FileName$", Path.GetFileName(project.FullPath) }, { "$SharePoint.Project.FileNameWithoutExtension$", Path.GetFileNameWithoutExtension(project.FullPath) }, { "$SharePoint.Package.Name$", Path.GetFileNameWithoutExtension(project.Package.OutputPath) }, { "$SharePoint.Package.FileName$", Path.GetFileName(project.Package.Name) }, { "$SharePoint.Package.FileNameWithoutExtension$", Path.GetFileNameWithoutExtension(project.Package.Name) }, { "$SharePoint.Package.Id$", project.Package.Id.ToString() }, { "$SharePoint.Project.AssemblyFullName$", assemblyName.FullName }, { "$SharePoint.Project.AssemblyFileName$", Path.GetFileName(project.OutputFullPath) }, { "$SharePoint.Project.AssemblyFileNameWithoutExtension$", Path.GetFileNameWithoutExtension(project.OutputFullPath) }, { "$SharePoint.Project.AssemblyPublicKeyToken$", string.Join(string.Empty, assemblyName.GetPublicKeyToken().Select(b => $"{b:x2}")) } }; this.ProjectTokenReplacements.Add(project.Id, tokens); } return(this.ProjectTokenReplacements[project.Id]); }
/// <summary> /// Imports the type of the content. /// </summary> /// <param name="contentTypeInfo">The content type info.</param> public static void ImportContentType(ContentTypeInfo contentTypeInfo) { if (contentTypeInfo != null) { //Create the encoding definition XDeclaration declaration = new XDeclaration("1.0", Encoding.UTF8.WebName, null); XNamespace sharepointToolsNamespace = @"http://schemas.microsoft.com/VisualStudio/2010/SharePointTools/SharePointProjectItemModel"; XNamespace sharepointNamespace = @"http://schemas.microsoft.com/sharepoint/"; XElement elementsFileContents = XElement.Parse(BuildElements(contentTypeInfo, declaration, sharepointNamespace)); EnvDTE.Project activeProject = DTEManager.ActiveProject; if (activeProject != null) { ISharePointProjectService projectService = DTEManager.ProjectService; ISharePointProject activeSharePointProject = DTEManager.ActiveSharePointProject; if (activeSharePointProject != null) { ISharePointProjectItem contentTypeProjectItem = activeSharePointProject.ProjectItems.Add(contentTypeInfo.Name, "Microsoft.VisualStudio.SharePoint.ContentType"); System.IO.File.WriteAllText(Path.Combine(contentTypeProjectItem.FullPath, "Elements.xml"), elementsFileContents.ToString().Replace("xmlns=\"\"", String.Empty)); ISharePointProjectItemFile elementsXml = contentTypeProjectItem.Files.AddFromFile("Elements.xml"); elementsXml.DeploymentType = DeploymentType.ElementManifest; elementsXml.DeploymentPath = String.Format(@"{0}\", contentTypeInfo.Name); contentTypeProjectItem.DefaultFile = elementsXml; } } } }
internal static string GetStartupUrl(DTE dte, Project project) { try { ISharePointProjectService projectService = Helpers2.GetSharePointProjectService(dte); if (project != null) { try { //set url for current project ISharePointProject sharePointProject = projectService.Convert <EnvDTE.Project, ISharePointProject>(project); if (sharePointProject.StartupUrl != null) { return(sharePointProject.StartupUrl.ToString()); } return(sharePointProject.SiteUrl.ToString()); } catch { } } } catch { } return(Helpers.GetApplicationConfigValue(dte, "StartupUrl", Helpers.GetApplicationConfigValue(dte, "DebuggingWebApp", "").ToString()).ToString()); }
/// <summary> /// Copies the file. /// </summary> /// <param name="project">The project.</param> /// <param name="fileName">Name of the file.</param> /// <param name="source">The source.</param> /// <param name="target">The target.</param> public static void CopyFile(ISharePointProject project, string fileName, string source, string target) { // Log the copy using the project and hive-relative formats. source = Path.Combine(source, fileName); target = Path.Combine(target, fileName); project.ProjectService.Logger.ActivateOutputWindow(); project.ProjectService.Logger.WriteLine(string.Format("{0} -> {1}", source, target), LogCategory.Status); // Now replace the project and hive tokens ready for the actual copy. string fullSource = SubstituteRootTokens(project, source); string fullTarget = SubstituteRootTokens(project, target); // Now create the directory and copy the files. try { Directory.CreateDirectory(Path.GetDirectoryName(fullTarget)); if (File.Exists(fullTarget)) { //Remove any read only attribute. EnsureFileIsNotReadOnly(fullTarget); File.Delete(fullTarget); } File.Copy(fullSource, fullTarget, true); EnsureFileIsNotReadOnly(fullTarget); } catch (Exception ex) { project.ProjectService.Logger.ActivateOutputWindow(); project.ProjectService.Logger.WriteLine("EXCEPTION: " + ex.Message, LogCategory.Error); } }
/// <summary> /// Copies to GAC. /// </summary> /// <param name="project">The project.</param> /// <param name="assemblyFullPath">The assembly full path.</param> public void CopyToGAC(ISharePointProject project, string assemblyFullPath) { //For more info on the GACUtil.exe http://msdn.microsoft.com/en-gb/library/ex0ss12c(v=vs.110).aspx StartProcess(project, "c:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v8.0A\\bin\\NETFX 4.0 Tools\\gacutil.exe", string.Format(@"/if ""{0}""", assemblyFullPath)); }
// A project is loaded in the IDE. void projectService_ProjectInitialized(object sender, SharePointProjectEventArgs e) { ISharePointProject project = (ISharePointProject)sender; string message = String.Format("The following project is being initialized: {0}", e.Project.Name); project.ProjectService.Logger.WriteLine(message, LogCategory.Message); }
/// <summary> /// Finds the name of the SPI item by. /// </summary> /// <param name="spiName">Name of the spi.</param> /// <param name="project">The project.</param> /// <returns></returns> public static ISharePointProjectItem FindSPIItemByName(string spiName, ISharePointProject project) { return((from ISharePointProjectItem spi in project.ProjectItems where spi.Name == spiName select spi).FirstOrDefault()); }
// The name of a project was changed. void projectService_ProjectNameChanged(object sender, NameChangedEventArgs e) { ISharePointProject project = (ISharePointProject)sender; string message = String.Format("The project named {0} was changed to {1}.", e.OldName, project.Name); project.ProjectService.Logger.WriteLine(message, LogCategory.Message); }
/// <summary> /// Create the wizard forms /// </summary> /// <param name="designTimeEnvironment">The design time environment</param> /// <param name="runKind">The wizard run kind</param> /// <returns>The IWizardFormExtension</returns> public override IWizardFormExtension CreateWizardForm(DTE designTimeEnvironment, WizardRunKind runKind) { //TODO: put this back _deploymentProperties = new DeploymentProperties(); ArtifactWizardForm wiz = new ArtifactWizardForm(designTimeEnvironment, CKSProperties.WebTemplate_WizardTitle); if (runKind == WizardRunKind.AsNewProject) { _webTemplateProperties = new WebTemplateProperties(Guid.NewGuid(), _deploymentProperties); DeploymentPresentationModel model = new DeploymentPresentationModel(_deploymentProperties, false, IsSharePointConnectionRequired); WebTemplatePresentationModel model2 = new WebTemplatePresentationModel(_webTemplateProperties, false, designTimeEnvironment); DeploymentPage page = new DeploymentPage(wiz, model); WebTemplatePage page2 = new WebTemplatePage(wiz, model2); wiz.AddPage(page); wiz.AddPage(page2); return(wiz); } ISharePointProject spProject = DTEManager.ActiveSharePointProject; _deploymentProperties.IsSandboxedSolution = spProject.IsSandboxedSolution; _deploymentProperties.Url = spProject.SiteUrl; _projectName = spProject.Name; _webTemplateProperties = new WebTemplateProperties(Guid.NewGuid(), _deploymentProperties); _webTemplateProperties.Title = _rootName; WebTemplatePresentationModel model3 = new WebTemplatePresentationModel(_webTemplateProperties, false, designTimeEnvironment); WebTemplatePage page5 = new WebTemplatePage(wiz, model3); wiz.AddPage(page5); return(wiz); }
/// <summary> /// Detects if a project is a SharePoint project based on a list of project type GUIDs. /// </summary> public static bool IsSharePointProject(EnvDTE.Project project, bool requireFarm) { //TODO: move this into the project utilities try { ISharePointProjectService projectService = DTEManager.ProjectService; if (projectService != null) { // Convert the DTE project into a SharePoint project. If the conversion fails, this is not a SP project. ISharePointProject p = projectService.Convert <EnvDTE.Project, Microsoft.VisualStudio.SharePoint.ISharePointProject>(project); if (p != null && requireFarm) { return(!p.IsSandboxedSolution); } else { return(p != null); } } } catch { // Must be VERY careful not to throw exceptions in here, since this is called on every click of the context menu. } return(false); }
// A project was removed or unloaded. void projectService_ProjectDisposing(object sender, SharePointProjectEventArgs e) { ISharePointProject project = (ISharePointProject)sender; string message = String.Format("The following project was removed or unloaded: {0}", e.Project.Name); project.ProjectService.Logger.WriteLine(message, LogCategory.Message); }
// Populate the SiteUrl and IsSandboxedSolution properties in the new project, and add a new // key.snk file to the project. public void ProjectFinishedGenerating(Project project) { ISharePointProject sharePointProject = presentationModel.ProjectService.Convert <Project, ISharePointProject>(project); sharePointProject.SiteUrl = new Uri(presentationModel.CurrentSiteUrl, UriKind.Absolute); sharePointProject.IsSandboxedSolution = presentationModel.IsSandboxed; signingManager.AddKeyFile(project); }
/// <summary> /// Set the project properties /// </summary> /// <param name="project">The project</param> public override void SetProjectProperties(EnvDTE.Project project) { ISharePointProject spProject = DTEManager.ProjectService.Convert <EnvDTE.Project, Microsoft.VisualStudio.SharePoint.ISharePointProject>(project); spProject.SiteUrl = _deploymentProperties.Url; spProject.IsSandboxedSolution = _deploymentProperties.IsSandboxedSolution; spProject.StartupItem = Enumerable.FirstOrDefault <ISharePointProjectItem>(ProjectUtilities.GetItemsOfType(spProject, ProjectItemIds.WebTemplate)); }
// A project property value was changed. private void projectService_ProjectPropertyChanged(object sender, PropertyChangedEventArgs e) { ISharePointProject project = (ISharePointProject)sender; string message = String.Format("The following property of the {0} project was changed: {1}", project.Name, e.PropertyName); project.ProjectService.Logger.WriteLine(message, LogCategory.Message); }
/// <summary> /// Loads the packages. /// </summary> /// <param name="project">The project.</param> private void LoadPackages(ISharePointProject project) { allPackages = new List <ISharePointProjectPackage>(); foreach (var p in project.ProjectService.Projects) { allPackages.Add(p.Package); } }
/// <summary> /// Initializes a new instance of the <see cref="SharePointProjectListItem" /> class. /// </summary> /// <param name="project">The project.</param> /// <exception cref="System.ArgumentNullException">project</exception> public SharePointProjectListItem(ISharePointProject project) { if (project == null) { throw new ArgumentNullException("project"); } Project = project; }
/// <summary> /// Gets the name of the assembly. /// </summary> /// <returns></returns> public static string GetAssemblyName(ISharePointProject project) { string outputFullPath = project.OutputFullPath; if (File.Exists(outputFullPath)) { return(AssemblyName.GetAssemblyName(outputFullPath).FullName); } return(Path.GetFileNameWithoutExtension(outputFullPath)); }
private void ChangeDeploymentTarget(ISharePointProject sharePointProject, string deploymentTarget) { if (deploymentTarget.Equals("GAC", StringComparison.InvariantCultureIgnoreCase) || deploymentTarget.Equals("GlobalAssemblyCache", StringComparison.InvariantCultureIgnoreCase)) { sharePointProject.AssemblyDeploymentTarget = AssemblyDeploymentTarget.GlobalAssemblyCache; } else { sharePointProject.AssemblyDeploymentTarget = AssemblyDeploymentTarget.WebApplication; } }
private void menuItem1_Click(object sender, MenuItemEventArgs e) { ISharePointProject project = (ISharePointProject)e.Owner; //<Snippet13> IVsBuildPropertyStorage projectStorage = project.ProjectService.Convert <ISharePointProject, IVsBuildPropertyStorage>(project); projectStorage.SetPropertyValue("MyCustomProperty", string.Empty, (uint)_PersistStorageType.PST_PROJECT_FILE, "Custom property value"); //</Snippet13> }
void MenuItemExtension_Click(object sender, MenuItemEventArgs e) { ISharePointProject project = e.Owner as ISharePointProject; if (project != null) { project.ProjectService.Logger.WriteLine( String.Format("This message was written from a shortcut menu for the {0} project.", project.Name), LogCategory.Status); } }
/// <summary> /// Initializes a new instance of the <see cref="PackagesViewerForm" /> class. /// </summary> /// <param name="project">The project.</param> /// <exception cref="System.ArgumentNullException">project</exception> public PackagesViewerForm(ISharePointProject project) { if (project == null) { throw new ArgumentNullException("project"); } InitializeComponent(); LoadPackages(project); FilterPackagesList(); }
/// <summary> /// Is the token replacement file. /// </summary> /// <param name="project">The SharePoint project to get the token replacement values for.</param> /// <param name="fileName">The file name.</param> /// <returns>True if its valid for token replacment.</returns> public static bool IsTokenReplacementFile(ISharePointProject project, string fileName) { List <string> fileExtensionsForTokenisation = ProjectUtilities.GetTokenReplacementFileExtension(project.ProjectService.Convert <ISharePointProject, EnvDTE.Project>(project)); string ext = Path.GetExtension(fileName).ToLower(); ext = ext.Replace(".", ""); return(fileExtensionsForTokenisation.Contains(ext)); }
/// <summary> /// Handles the Click event of the copyAssemblyNameItem control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="Microsoft.VisualStudio.SharePoint.MenuItemEventArgs"/> instance containing the event data.</param> void copyAssemblyNameItem_Click(object sender, MenuItemEventArgs e) { ISharePointProject project = e.Owner as ISharePointProject; EnvDTE.Project dteProject = DTEManager.ProjectService.Convert <ISharePointProject, EnvDTE.Project>(project); if (dteProject.DTE.Solution.SolutionBuild.BuildState != vsBuildState.vsBuildStateInProgress) { dteProject.DTE.Solution.SolutionBuild.BuildProject(dteProject.DTE.Solution.SolutionBuild.ActiveConfiguration.Name, dteProject.UniqueName, true); Clipboard.SetText(ProjectUtilities.GetAssemblyName(project)); } }
/// <summary> /// Substitutes the root tokens. /// </summary> /// <param name="project">The project.</param> /// <param name="name">The name.</param> /// <returns></returns> internal static string SubstituteRootTokens(ISharePointProject project, string name) { name = name.Replace("{ProjectRoot}", Path.GetDirectoryName(project.FullPath)).Replace("\\\\", "\\"); name = name.Replace("{SharePointRoot}", project.ProjectService.SharePointInstallPath).Replace("\\\\", "\\"); // for performance reasons we don't want to execute command unless we really have to replace the token if (name.Contains("{WebApplicationRoot}")) { String webApplicationRoot = project.SharePointConnection.ExecuteCommand <String>("Microsoft.VisualStudio.SharePoint.Commands.GetWebApplicationLocalPath"); name = name.Replace("{WebApplicationRoot}", webApplicationRoot).Replace("\\\\", "\\"); } return(name); }
void ImportListInstanceExplorerExtension_Click(object sender, MenuItemEventArgs e) { IExplorerNode listNode = e.Owner as IExplorerNode; if (listNode != null) { try { IListNodeInfo listInfo = listNode.Annotations.GetValue <IListNodeInfo>(); string listInstanceContents = listNode.Context.SharePointConnection.ExecuteCommand <Guid, string>(CommandIds.GetListInstanceXmlCommandId, listInfo.Id); XNamespace xn = "http://schemas.microsoft.com/sharepoint/"; string moduleContents = new XElement(xn + "Elements", XElement.Parse(listInstanceContents)).ToString().Replace(" xmlns=\"\"", String.Empty); EnvDTE.Project activeProject = Utils.GetActiveProject(); if (activeProject != null) { ISharePointProjectService projectService = listNode.ServiceProvider.GetService(typeof(ISharePointProjectService)) as ISharePointProjectService; ISharePointProject activeSharePointProject = projectService.Projects[activeProject.FullName]; if (activeSharePointProject != null) { string spiName = listInfo.Title; ISharePointProjectItem listInstanceProjectItem = null; bool itemCreated = false; int counter = 0; do { try { listInstanceProjectItem = activeSharePointProject.ProjectItems.Add(spiName, "Microsoft.VisualStudio.SharePoint.ListInstance"); itemCreated = true; } catch (ArgumentException) { spiName = String.Format("{0}{1}", listInfo.Title, ++counter); } }while (!itemCreated); string elementsXmlFullPath = Path.Combine(listInstanceProjectItem.FullPath, "Elements.xml"); System.IO.File.WriteAllText(elementsXmlFullPath, moduleContents); ISharePointProjectItemFile elementsXml = listInstanceProjectItem.Files.AddFromFile("Elements.xml"); elementsXml.DeploymentType = DeploymentType.ElementManifest; elementsXml.DeploymentPath = String.Format(@"{0}\", spiName); listInstanceProjectItem.DefaultFile = elementsXml; Utils.OpenFile(Path.Combine(elementsXmlFullPath)); } } } catch (Exception ex) { listNode.Context.ShowMessageBox(String.Format("The following exception occured while exporting List Instance: {0}", ex.Message), MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
/// <summary> /// Imports the field. /// </summary> /// <param name="fieldNode">The field node.</param> /// <exception cref="System.ArgumentNullException"></exception> public static void ImportField(IExplorerNode fieldNode) { if (fieldNode == null) { throw new ArgumentNullException("fieldNode"); } Microsoft.VisualStudio.SharePoint.Explorer.Extensions.IFieldNodeInfo nodeInfo = fieldNode.Annotations.GetValue <Microsoft.VisualStudio.SharePoint.Explorer.Extensions.IFieldNodeInfo>(); if (nodeInfo != null) { FieldNodeInfo fieldNodeInfo = new FieldNodeInfo { ContentTypeName = nodeInfo.ContentTypeName, Id = nodeInfo.Id, IsHidden = nodeInfo.IsHidden, ListId = nodeInfo.ListId, Title = nodeInfo.Title }; Dictionary <string, string> fieldProperties = null; if (String.IsNullOrEmpty(fieldNodeInfo.ContentTypeName) && fieldNodeInfo.ListId == Guid.Empty) { fieldProperties = fieldNode.Context.SharePointConnection.ExecuteCommand <FieldNodeInfo, Dictionary <string, string> >(SiteColumnsSharePointCommandIds.GetProperties, fieldNodeInfo); } else { fieldProperties = fieldNode.Context.SharePointConnection.ExecuteCommand <FieldNodeInfo, Dictionary <string, string> >(FieldSharePointCommandIds.GetProperties, fieldNodeInfo); } if (fieldProperties != null) { XNamespace xn = XNamespace.Get("http://schemas.microsoft.com/sharepoint/"); XElement xElements = new XElement(xn + "Elements", XElement.Parse(fieldProperties["SchemaXml"])); EnvDTE.Project activeProject = DTEManager.ActiveProject; if (activeProject != null) { ISharePointProjectService projectService = fieldNode.ServiceProvider.GetService(typeof(ISharePointProjectService)) as ISharePointProjectService; ISharePointProject activeSharePointProject = projectService.Projects[activeProject.FullName]; if (activeSharePointProject != null) { ISharePointProjectItem fieldProjectItem = activeSharePointProject.ProjectItems.Add(fieldProperties["InternalName"], "Microsoft.VisualStudio.SharePoint.Field"); System.IO.File.WriteAllText(Path.Combine(fieldProjectItem.FullPath, "Elements.xml"), xElements.ToString().Replace("xmlns=\"\"", String.Empty)); ISharePointProjectItemFile elementsXml = fieldProjectItem.Files.AddFromFile("Elements.xml"); elementsXml.DeploymentType = DeploymentType.ElementManifest; elementsXml.DeploymentPath = String.Format(@"{0}\", fieldProperties["InternalName"]); fieldProjectItem.DefaultFile = elementsXml; } } } } }
private string ReplacePathTokens(ISharePointProject project, string path) { path = path.Replace("{ProjectRoot}", Path.GetDirectoryName(project.FullPath)).Replace("\\\\", "\\"); path = path.Replace("{SharePointRoot}", project.ProjectService.SharePointInstallPath).Replace("\\\\", "\\"); if (path.Contains("{WebApplicationRoot}")) { var webApplicationRoot = project.SharePointConnection.ExecuteCommand <String>("Microsoft.VisualStudio.SharePoint.Commands.GetWebApplicationLocalPath"); path = path.Replace("{WebApplicationRoot}", webApplicationRoot).Replace("\\\\", "\\"); } return(path); }
/// <summary> /// Loads the projects. /// </summary> /// <param name="project">The project.</param> private void LoadProjects(ISharePointProject project) { List <SharePointProjectListItem> projects = (from ISharePointProject p in project.ProjectService.Projects select new SharePointProjectListItem(p)).OrderBy(pr => pr.Project.Name).ToList(); Project.Items.Add(""); foreach (var p in projects) { Project.Items.Add(p); } }
public override void Execute() { if (string.IsNullOrEmpty(SiteUrl)) { return; } EnvDTE.DTE service = this.GetService <EnvDTE.DTE>(true); if (!string.IsNullOrEmpty(CurrentProjectName)) { CurrentProject = Helpers.GetProjectByName(service, CurrentProjectName); } try { ISharePointProjectService projectService = Helpers2.GetSharePointProjectService(service); if (CurrentProject != null) { try { //set url for current project ISharePointProject sharePointProject = projectService.Convert <EnvDTE.Project, ISharePointProject>(CurrentProject); sharePointProject.SiteUrl = new Uri(SiteUrl); } catch { } } else { //set url for all projects foreach (ISharePointProject sharePointProject in projectService.Projects) { try { if (sharePointProject.SiteUrl == null) { sharePointProject.SiteUrl = new Uri(SiteUrl); Helpers.LogMessage(service, this, "Settings site url of project " + sharePointProject.Name + " to " + new Uri(SiteUrl).ToString()); } } catch (Exception) { Helpers.LogMessage(service, this, "Could not set site url of project " + sharePointProject.Name + " to " + new Uri(SiteUrl).ToString()); } } } } catch { } }
/// <summary> /// Determines whether [is share point project] [the specified project]. /// </summary> /// <param name="project">The project.</param> /// <param name="requireFarm">if set to <c>true</c> [require farm].</param> /// <returns> /// <c>true</c> if [is share point project] [the specified project]; otherwise, <c>false</c>. /// </returns> public static bool IsSharePointProject(EnvDTE.Project project, bool requireFarm) { // Convert the DTE project into a SharePoint project. If the conversion fails, this is not a SP project. ISharePointProject p = ProjectService.Convert <EnvDTE.Project, Microsoft.VisualStudio.SharePoint.ISharePointProject>(project); if (p != null && requireFarm) { return(!p.IsSandboxedSolution); } else { return(p != null); } }