/// <summary> /// /// </summary> /// <param name="activeProject"></param> /// <param name="identifier"></param> /// <param name="showDialog"></param> /// <param name="userChoice"></param> /// <param name="hadConfig"></param> /// <param name="filepath"></param> /// <returns></returns> public Xml.Settings.Project.Options DetermineProjectConfiguration(Project activeProject, Enumerations.ProjectIdentifier identifier, out string filepath, bool returnClone) { filepath = null; //-----get the user project settings and check if they are set to Xml.Settings.Project.Options projectOptions = Configuration.ProjectOptions.First(x => x.Identifier == identifier); if (projectOptions.GeneralOptions.Storage == Enumerations.SettingsStorage.Project) { string configName = Resources.ProjectConfigurationFilename; if (!string.IsNullOrEmpty(projectOptions.GeneralOptions.Filename)) { configName = projectOptions.GeneralOptions.Filename; if (string.IsNullOrEmpty(Path.GetExtension(configName))) { configName = string.Format("{0}.config", configName); } } LoggingManager.Instance.Logger.Debug(string.Format("configuration filename is: {0}", configName)); ProjectItem config = ExtensionUtil.GetItem(configName, activeProject.ProjectItems); if (config == null) { LoggingManager.Instance.Logger.Debug("configuration file not found, using existing configuration"); filepath = Path.Combine(Path.GetDirectoryName(activeProject.FullName), configName); XmlUtil.Serialize(filepath, Configuration.ProjectOptions.First(x => x.Identifier == identifier)); activeProject.ProjectItems.AddFromFile(filepath); activeProject.Save(); } else { filepath = ExtensionUtil.GetPropertyValue <string>(config.Properties, Resources.PropertyFullpath, null); } return(XmlUtil.Deserialize <Xml.Settings.Project.Options>(filepath)); } else { Xml.Settings.Project.Options original = Configuration.ProjectOptions.First(x => x.Identifier == identifier); if (original != null) { if (returnClone) { return(original.Clone()); } else { return(original); } } return(null); } }
/// <summary> /// prepares the project and stores all the needed information in local variables /// </summary> /// <param name="activeProject">project that is supposed to be deployed, must not be null</param> /// <returns>null if the preparation was successfull, otherwise the error string</returns> private void PreAnalyseProject(Project activeProject, out PackageInformation packageInfo, out ProjectInformation projectInformation) { LoggingManager.Instance.Logger.Debug("prepare project started"); if (activeProject == null) { throw new ArgumentNullException("activeProject", "given project must not be null"); } //-----assign incoming values packageInfo = null; projectInformation = null; //-----make sure the project is supported projectInformation = OptionsManager.Instance.SupportedProjectInformation.FirstOrDefault(p => activeProject.FullName.EndsWith(p.Extension)); if (projectInformation == null) { throw new ProjectNoSupportedException("project not supported"); } //-----make sure the project is not being deployed already try { if (Mutex.OpenExisting(activeProject.FullName.GetHashCode().ToString()) != null) { throw new ProjectIsBeingDeployedException("project is already being deployed"); } } catch (WaitHandleCannotBeOpenedException) { LoggingManager.Instance.Logger.Debug(string.Format("project {0} is currently not being deployed", activeProject.FullName)); } //-----get the project options, which will either be used or project based string configFullName; Enumerations.ProjectIdentifier identifier = projectInformation.Identifier; Xml.Settings.Project.Options projectOptions = OptionsManager.Instance.DetermineProjectConfiguration(activeProject, identifier, out configFullName, true); //-----create the deployment info packageInfo = new PackageInformation() { ProjectOptions = projectOptions, NuSpecPackage = new Xml.NuGet.NuSpec.Package() { Metadata = new Xml.NuGet.NuSpec.Metadata() }, Build = new BuildOptions(), ProjectFullName = activeProject.FullName, }; LoggingManager.Instance.Logger.Debug("prepare project finished"); }
/// <summary> /// initializes all the properties based on the identifier /// </summary> /// <param name="identifier"></param> public ProjectInformation(Enumerations.ProjectIdentifier identifier) { Identifier = identifier; switch (Identifier) { case Enumerations.ProjectIdentifier.CPP: Extension = ".vcxproj"; FileExtension = ".cpp"; AssemblyName = "AssemblyInfo"; AssemblyInfoIdentifier = "[assembly:"; Id = "Name"; Title = "AssemblyTitle"; Authors = "AssemblyCompany"; Description = "AssemblyDescription"; Language = "NeutralResourcesLanguage"; Copyright = "AssemblyCopyright"; Moniker = "TargetFrameworkMoniker"; OutputFileName = "Name"; OutputPath = "OutputPath"; ItemType = "ItemType"; ItemOutput = "DeploymentContent"; ValidItemTypes = new List <string>() { "ClCompile", "Text", }; break; case Enumerations.ProjectIdentifier.CS: Extension = ".csproj"; FileExtension = ".cs"; AssemblyName = "AssemblyInfo"; AssemblyInfoIdentifier = "[assembly:"; Id = "AssemblyName"; Title = "AssemblyTitle"; Authors = "AssemblyCompany"; Description = "AssemblyDescription"; Language = "NeutralResourcesLanguage"; Copyright = "AssemblyCopyright"; Moniker = "TargetFrameworkMoniker"; OutputFileName = "OutputFileName"; OutputPath = "OutputPath"; Optimize = "Optimize"; DefineConstants = "DefineConstants"; DebugInfo = "DebugInfo"; ItemType = "ItemType"; ItemOutput = "CopyToOutputDirectory"; ValidItemTypes = new List <string>() { "None", "Compile", "Content", "EmbeddedResource", "CodeAnalysisDictionary", "ApplicationDefinition", "Page", "Resource", "SplashScreen", "DesignData", "DesignDataWithDesignTimeCreatableTypes", "EntityDeploy", "XamlAppDef", "Fakes", }; break; case Enumerations.ProjectIdentifier.VB: Extension = ".vbproj"; FileExtension = ".vb"; AssemblyName = "AssemblyInfo"; AssemblyInfoIdentifier = "<Assembly:"; Id = "AssemblyName"; Title = "AssemblyTitle"; Authors = "AssemblyCompany"; Description = "AssemblyDescription"; Language = "NeutralResourcesLanguage"; Copyright = "AssemblyCopyright"; Moniker = "TargetFrameworkMoniker"; OutputFileName = "OutputFileName"; OutputPath = "OutputPath"; Optimize = "Optimize"; DefineConstants = "DefineConstants"; DebugInfo = "DebugInfo"; ItemType = "ItemType"; ItemOutput = "CopyToOutputDirectory"; ValidItemTypes = new List <string>() { "None", "Compile", "Content", "EmbeddedResource", "CodeAnalysisDictionary", "ApplicationDefinition", "Page", "Resource", "SplashScreen", "DesignData", "DesignDataWithDesignTimeCreatableTypes", "EntityDeploy", "XamlAppDef", "Fakes", }; break; } }
/// <summary> /// element callback for settings files of version 1.1.0.0 /// </summary> /// <param name="element">element that has been read</param> /// <param name="value">value of the xmlelement</param> public override void ElementCallback(Element element) { try { //-----Metadata if (element.Parent != null && element.Parent.Name == "ProjectOptions" && element.Parent.Parent != null && element.Parent.Parent.Name == "GeneralOptions") { if (element.Attributes.ContainsKey("identifier")) { Enumerations.ProjectIdentifier identifier = (Enumerations.ProjectIdentifier)Enum.Parse(typeof(Enumerations.ProjectIdentifier), element.Attributes["identifier"]); Project.Options projectOptions = _configuration.ProjectOptions.FirstOrDefault(x => x.Identifier == identifier); if (projectOptions == null) { projectOptions = new Project.Options() { Identifier = identifier }; _configuration.ProjectOptions.Add(projectOptions); } if (element.Attributes.ContainsKey("storage")) { projectOptions.GeneralOptions.Storage = (Enumerations.SettingsStorage)Enum.Parse(typeof(Enumerations.SettingsStorage), element.Attributes["storage"]); } if (element.Attributes.ContainsKey("filename")) { projectOptions.GeneralOptions.Filename = element.Attributes["filename"]; } } } else if (element.Name == "Increment" && element.Parent != null && element.Parent.Name == "GeneralOptions" && element.Parent.Parent != null && element.Parent.Parent.Name == "ProjectOption") { if (element.Parent.Parent.Attributes.ContainsKey("identifier")) { Enumerations.ProjectIdentifier identifier = (Enumerations.ProjectIdentifier)Enum.Parse(typeof(Enumerations.ProjectIdentifier), element.Parent.Parent.Attributes["identifier"]); Project.Options projectOptions = _configuration.ProjectOptions.FirstOrDefault(x => x.Identifier == identifier); if (projectOptions == null) { projectOptions = new Project.Options() { Identifier = identifier }; _configuration.ProjectOptions.Add(projectOptions); } if (element.Value != "None") { projectOptions.GeneralOptions.VersionComponent = (Common.Definitions.Enumerations.VersionComponent)Enum.Parse(typeof(Common.Definitions.Enumerations.VersionComponent), element.Value); } } } else if (element.Parent != null && element.Parent.Name == "Servers" && element.Name == "Server") { General.NuGet.Server server = _configuration.GeneralOptions.NuGetOptions.Servers.FirstOrDefault(x => x.Url == element.Attributes["url"]); if (server == null) { server = new General.NuGet.Server() { Url = element.Attributes["url"], ApiKey = ExtensionManager.Instance.Encryptor.Encrypt(element.Attributes["apiKey"]), IsPreferred = System.Convert.ToBoolean(element.Attributes["isPreferred"]), LastAttemptedDeploy = System.Convert.ToDateTime(element.Attributes["lastAttemptedDeploy"]), LastSuccessfulDeploy = System.Convert.ToDateTime(element.Attributes["lastSuccessfulDeploy"]) }; _configuration.GeneralOptions.NuGetOptions.Servers.Add(server); } else { server.ApiKey = ExtensionManager.Instance.Encryptor.Encrypt(server.ApiKey); } } } catch (Exception ex) { LoggingManager.Instance.Logger.Warn(string.Format("could not convert element [{0}] with value [{1}]", element.Name, element.Value), ex); } }