/// <summary> /// will be called once a gui element of the nuspec files tabpage was changed /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnChangeNuSpecFiles(object sender, EventArgs e) { if (sender == _uiNuSpecFilesItems) { Xml.NuGet.NuSpec.File nuSpecFile = (Xml.NuGet.NuSpec.File)_uiNuSpecFilesItems.SelectedItem; _uiNuSpecFilesSearch.Enabled = nuSpecFile != null; _uiNuSpecFilesRemove.Enabled = nuSpecFile != null; _uiNuSpecFilesChange.Enabled = false; CanDeploy(); } else if (sender == _uiNuSpecFilesSource || sender == _uiNuSpecFilesTarget || sender == _uiNuSpecFilesExclude) { Xml.NuGet.NuSpec.File nuSpecFile = (Xml.NuGet.NuSpec.File)_uiNuSpecFilesItems.SelectedItem; if (nuSpecFile != null) { _uiNuSpecFilesChange.Enabled = (!Utils.StringUtil.EqualsOrNullAndEmpty(nuSpecFile.Source, _uiNuSpecFilesSource.Text) || !Utils.StringUtil.EqualsOrNullAndEmpty(nuSpecFile.Target, _uiNuSpecFilesTarget.Text) || !Utils.StringUtil.EqualsOrNullAndEmpty(nuSpecFile.Exclude, _uiNuSpecFilesExclude.Text)); } else { _uiNuSpecFilesChange.Enabled = false; } } }
/// <summary> /// determines the nuspec files to add from the project /// </summary> private void DetermineNuSpecFiles(Project activeProject, PackageInformation packageInfo, ProjectInformation projectInformation, Xml.Settings.General.NuGet.Target nuGetTarget) { LoggingManager.Instance.Logger.Debug("determine nuspec files started"); //-----add the assembly file packageInfo.NuSpecPackage.Files = new List <Xml.NuGet.NuSpec.File>(); packageInfo.NuSpecPackage.Files.Add(new Xml.NuGet.NuSpec.File() { Source = Path.Combine(packageInfo.Build.BuildPath, packageInfo.OutputFileName), Target = string.Format(@"lib\{0}", nuGetTarget.Name) }); //-----add the pdb file only if the debug useage is used and the value is known if (packageInfo.ProjectOptions.MsBuildOptions.Usage.DebugInfo.Useage != Enumerations.Useage.None) { string source = Path.Combine(packageInfo.Build.BuildPath, StringUtil.ReplaceLastOccurrence(packageInfo.OutputFileName, Resources.ExtensionDLL, Resources.ExtensionPDB)); Xml.NuGet.NuSpec.File pdbFile = new Xml.NuGet.NuSpec.File() { Source = source, Target = string.Format(@"lib\{0}", nuGetTarget.Name) }; packageInfo.Build.PdbFiles.Add(pdbFile); if (packageInfo.Build.DebugInfo == Resources.DebugInfoPdbOnly || packageInfo.Build.DebugInfo == Resources.DebugInfoFull) { packageInfo.NuSpecPackage.Files.Add(pdbFile); } } //HACK this is needed since VB does not implement the documentation file the way CS does it, need to find a work arround if (projectInformation.Identifier == Enumerations.ProjectIdentifier.CS) { //include documentation files if needed foreach (string documentationFileUrl in ExtensionUtil.GetFilenames(activeProject.ConfigurationManager.ActiveConfiguration, Definitions.Constants.DocumentaionOutputGroupCanonicalName)) { Xml.NuGet.NuSpec.File documentationFile = new Xml.NuGet.NuSpec.File() { Source = documentationFileUrl, Target = string.Format(@"lib\{0}", nuGetTarget.Name) }; if (packageInfo.Build.DocumentationFile == null) { packageInfo.Build.DocumentationFile = documentationFile; } packageInfo.NuSpecPackage.Files.Add(documentationFile); } } //-----get all the includeable item here if (packageInfo.ProjectOptions.NuGetOptions.NuSpecOptions.Files.FileIncludes.Count > 0) { if (projectInformation.Identifier == Enumerations.ProjectIdentifier.CS || projectInformation.Identifier == Enumerations.ProjectIdentifier.VB) { AddNuSpecFilesCSharpVisualBasic(activeProject.ProjectItems, packageInfo, projectInformation); } } LoggingManager.Instance.Logger.Debug("determine nuspec files finished"); }
/// <summary> /// will be called when any button of the nuspec files tabpage was clicked /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnClickNuSpecFiles(object sender, EventArgs e) { if (sender == _uiNuSpecFilesAdd) { Xml.NuGet.NuSpec.File nuSpecFile = new Xml.NuGet.NuSpec.File() { Source = Configuration.Provider.NewEntryIndicator, Target = "lib" }; int i = 0; _nuSpecFilesBinding.ToList().ForEach(f => { if (f.Source == nuSpecFile.Source) { nuSpecFile.Source = String.Format("{0} {1}", Configuration.Provider.NewEntryIndicator, ++i); } }); _nuSpecFilesBinding.Add(nuSpecFile); _uiNuSpecFilesItems.SelectedItem = nuSpecFile; } else if (sender == _uiNuSpecFilesRemove) { _nuSpecFilesBinding.Remove((Xml.NuGet.NuSpec.File)_uiNuSpecFilesItems.SelectedItem); } else if (sender == _uiNuSpecFilesSearch) { try { _nuSpecFilesOpenFile.InitialDirectory = Path.GetDirectoryName(_uiNuSpecFilesSource.Text); } catch (Exception ex) { Logging.Manager.Instance.Logger.Warn(String.Format("could not set intial directory [{0}] for nuspec file", _uiNuSpecFilesSource.Text), ex); } if (_nuSpecFilesOpenFile.ShowDialog() == DialogResult.OK) { _uiNuSpecFilesSource.Text = _nuSpecFilesOpenFile.FileName; } } else if (sender == _uiNuSpecFilesChange) { Xml.NuGet.NuSpec.File nuSpecFile = (Xml.NuGet.NuSpec.File)_uiNuSpecFilesItems.SelectedItem; foreach (Xml.NuGet.NuSpec.File file in _nuSpecFilesBinding) { if (file.Source == _uiNuSpecFilesSource.Text && file != nuSpecFile) { MessageBox.Show("A nuspec file with the same source exists already, please change the source"); return; } } ; nuSpecFile.Source = _uiNuSpecFilesSource.Text; nuSpecFile.Target = _uiNuSpecFilesTarget.Text; nuSpecFile.Exclude = _uiNuSpecFilesExclude.Text; _uiNuSpecFilesChange.Enabled = false; CanDeploy(); typeof(ListBox).InvokeMember("RefreshItems", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod, null, _uiNuSpecFilesItems, new object[] { }); } }
/// <summary> /// determines the nuspec files to add from the project /// </summary> private void DetermineNuSpecFiles(Project activeProject, PackageInformation packageInfo, ProjectInformation projectInformation, Xml.Settings.General.NuGet.Target nuGetTarget) { LoggingManager.Instance.Logger.Debug("determine nuspec files started"); //-----add the assembly file packageInfo.NuSpecPackage.Files = new List<Xml.NuGet.NuSpec.File>(); packageInfo.NuSpecPackage.Files.Add(new Xml.NuGet.NuSpec.File() { Source = Path.Combine(packageInfo.Build.BuildPath, packageInfo.OutputFileName), Target = string.Format(@"lib\{0}", nuGetTarget.Name) }); //-----add the pdb file only if the debug useage is used and the value is known if (packageInfo.ProjectOptions.MsBuildOptions.Usage.DebugInfo.Useage != Enumerations.Useage.None) { string source = Path.Combine(packageInfo.Build.BuildPath, StringUtil.ReplaceLastOccurrence(packageInfo.OutputFileName, Resources.ExtensionDLL, Resources.ExtensionPDB)); Xml.NuGet.NuSpec.File pdbFile = new Xml.NuGet.NuSpec.File() { Source = source, Target = string.Format(@"lib\{0}", nuGetTarget.Name) }; packageInfo.Build.PdbFiles.Add(pdbFile); if (packageInfo.Build.DebugInfo == Resources.DebugInfoPdbOnly || packageInfo.Build.DebugInfo == Resources.DebugInfoFull) packageInfo.NuSpecPackage.Files.Add(pdbFile); } //HACK this is needed since VB does not implement the documentation file the way CS does it, need to find a work arround if (projectInformation.Identifier == Enumerations.ProjectIdentifier.CS) { //include documentation files if needed foreach (string documentationFileUrl in ExtensionUtil.GetFilenames(activeProject.ConfigurationManager.ActiveConfiguration, Definitions.Constants.DocumentaionOutputGroupCanonicalName)) { Xml.NuGet.NuSpec.File documentationFile = new Xml.NuGet.NuSpec.File() { Source = documentationFileUrl, Target = string.Format(@"lib\{0}", nuGetTarget.Name) }; if (packageInfo.Build.DocumentationFile == null) packageInfo.Build.DocumentationFile = documentationFile; packageInfo.NuSpecPackage.Files.Add(documentationFile); } } //-----get all the includeable item here if (packageInfo.ProjectOptions.NuGetOptions.NuSpecOptions.Files.FileIncludes.Count > 0) { if (projectInformation.Identifier == Enumerations.ProjectIdentifier.CS || projectInformation.Identifier == Enumerations.ProjectIdentifier.VB) AddNuSpecFilesCSharpVisualBasic(activeProject.ProjectItems, packageInfo, projectInformation); } LoggingManager.Instance.Logger.Debug("determine nuspec files finished"); }
/// <summary> /// build the project using the given msbuild exe /// </summary> /// <param name="msBuildPath">full path to the msbuild exe to use</param> /// <returns>true if the build process was successful, false otherwise</returns> private void BuildProject(DeploymentInformation deployInfo) { LoggingManager.Instance.Logger.Debug("building project"); //-----start the build process of the project string result; string error; if (!Directory.Exists(deployInfo.Build.BuildPath)) { LoggingManager.Instance.Logger.Debug(string.Format("creating directory {0}", deployInfo.Build.BuildPath)); Directory.CreateDirectory(deployInfo.Build.BuildPath); } string buildFileFullname = Path.Combine(deployInfo.Build.BuildPath, deployInfo.OutputFileName); StringBuilder command = new StringBuilder(string.Format(@"{0} ""{1}"" ", deployInfo.MsBuildFullName, deployInfo.ProjectFullName)); command.Append(string.Format(@" /p:Configuration=""{0}"" ", deployInfo.Build.ConfigurationName)); command.Append(string.Format(@" /p:Platform=""{0}"" ", deployInfo.Build.PlatformName)); command.Append(string.Format(@" /p:OutputPath=""{0}"" ", deployInfo.Build.BuildPath)); if (deployInfo.ProjectOptions.MsBuildOptions.Usage.Optimize.Useage != Enumerations.Useage.None && deployInfo.Build.Optimize != null) { command.Append(string.Format(@" /p:Optimize={0} ", deployInfo.Build.Optimize.ToString())); } if (deployInfo.ProjectOptions.MsBuildOptions.Usage.DebugConstants.Useage != Enumerations.Useage.None && !string.IsNullOrEmpty(deployInfo.Build.DebugConstants)) { command.Append(string.Format(@" /p:DefineConstants=""{0}"" ", deployInfo.Build.DebugConstants)); } if (deployInfo.ProjectOptions.MsBuildOptions.Usage.DebugInfo.Useage != Enumerations.Useage.None && !string.IsNullOrEmpty(deployInfo.Build.DebugInfo)) { command.Append(string.Format(@" /p:DebugSymbols=true /p:DebugType={0} ", deployInfo.Build.DebugInfo.ToString())); } if (deployInfo.Build.DocumentationFile != null) { command.Append(string.Format(@" /p:DocumentationFile=""{0}"" ", deployInfo.Build.DocumentationFile.Source)); } LoggingManager.Instance.Logger.Debug(string.Format("executing command [{0}]", command.ToString())); CommandUtil.ExecuteCommand(command.ToString(), new string[] { "/C" }, out result, out error); //-----make sure the build process was successfull if (!string.IsNullOrEmpty(error) || !File.Exists(buildFileFullname)) { //HACK should be reworked since it is not very save, but currently the only way if (string.IsNullOrEmpty(error) && deployInfo.ProjectOptions.Identifier == Enumerations.ProjectIdentifier.CPP) { Xml.NuGet.NuSpec.File fileDll = deployInfo.NuSpecPackage.Files.FirstOrDefault(f => f.Source == buildFileFullname); Xml.NuGet.NuSpec.File filePdb = deployInfo.NuSpecPackage.Files.FirstOrDefault(f => f.Source == StringUtil.ReplaceLastOccurrence(buildFileFullname, Resources.ExtensionDLL, Resources.ExtensionPDB)); if (fileDll != null) { deployInfo.Build.BuildPath = Path.Combine(Path.GetDirectoryName(deployInfo.ProjectFullName), deployInfo.Build.PlatformName, deployInfo.Build.ConfigurationName); buildFileFullname = Path.Combine(deployInfo.Build.BuildPath, deployInfo.OutputFileName); LoggingManager.Instance.Logger.Warn(string.Format("could not create the orignal file for cpp project, checking if file {0} exists", buildFileFullname)); if (File.Exists(buildFileFullname)) { fileDll.Source = buildFileFullname; if (filePdb != null) { filePdb.Source = StringUtil.ReplaceLastOccurrence(buildFileFullname, Resources.ExtensionDLL, Resources.ExtensionPDB); } XmlUtil.Serialize(deployInfo.NuSpecFileFullName, deployInfo.NuSpecPackage); return; } } } throw new ProjectBuildFailedExceptions(!string.IsNullOrEmpty(error) ? string.Format("An Error occured during the build process: {0}", error) : string.Format("Could not create file: {0}", buildFileFullname)); } LoggingManager.Instance.Logger.Debug("building project finished"); }
/// <summary> /// will be called when any button of the nuspec files tabpage was clicked /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnClickNuSpecFiles(object sender, EventArgs e) { if(sender == _uiNuSpecFilesAdd) { Xml.NuGet.NuSpec.File nuSpecFile = new Xml.NuGet.NuSpec.File() { Source = Configuration.Provider.NewEntryIndicator, Target = "lib" }; int i = 0; _nuSpecFilesBinding.ToList().ForEach(f => { if(f.Source == nuSpecFile.Source) nuSpecFile.Source = String.Format("{0} {1}", Configuration.Provider.NewEntryIndicator, ++i); }); _nuSpecFilesBinding.Add(nuSpecFile); _uiNuSpecFilesItems.SelectedItem = nuSpecFile; } else if(sender == _uiNuSpecFilesRemove) { _nuSpecFilesBinding.Remove((Xml.NuGet.NuSpec.File)_uiNuSpecFilesItems.SelectedItem); } else if(sender == _uiNuSpecFilesSearch) { try { _nuSpecFilesOpenFile.InitialDirectory = Path.GetDirectoryName(_uiNuSpecFilesSource.Text); } catch(Exception ex) { Logging.Manager.Instance.Logger.Warn(String.Format("could not set intial directory [{0}] for nuspec file", _uiNuSpecFilesSource.Text), ex); } if(_nuSpecFilesOpenFile.ShowDialog() == DialogResult.OK) _uiNuSpecFilesSource.Text = _nuSpecFilesOpenFile.FileName; } else if(sender == _uiNuSpecFilesChange) { Xml.NuGet.NuSpec.File nuSpecFile = (Xml.NuGet.NuSpec.File)_uiNuSpecFilesItems.SelectedItem; foreach(Xml.NuGet.NuSpec.File file in _nuSpecFilesBinding) { if(file.Source == _uiNuSpecFilesSource.Text && file != nuSpecFile) { MessageBox.Show("A nuspec file with the same source exists already, please change the source"); return; } }; nuSpecFile.Source = _uiNuSpecFilesSource.Text; nuSpecFile.Target = _uiNuSpecFilesTarget.Text; nuSpecFile.Exclude = _uiNuSpecFilesExclude.Text; _uiNuSpecFilesChange.Enabled = false; CanDeploy(); typeof(ListBox).InvokeMember("RefreshItems", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod, null, _uiNuSpecFilesItems, new object[] { }); } }