Example #1
0
		/// <summary>
		/// Initializes a new instance of the <see cref="Project"/> class.
		/// </summary>
		/// <param name="serializer">The serializer to use for saving the project.</param>
		/// <param name="buildSettings">Contains build-related settings.</param>
		protected Project(ProjectSerializer serializer, BuildSettings buildSettings)
		{
			Tracer.VerifyNonNullArgument(serializer, "serializer");
			Tracer.VerifyNonNullArgument(buildSettings, "buildSettings");
			this.serializer = serializer;
			this.buildSettings = buildSettings;
		}
Example #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Project"/> class.
 /// </summary>
 /// <param name="serializer">The serializer to use for saving the project.</param>
 /// <param name="buildSettings">Contains build-related settings.</param>
 protected Project(ProjectSerializer serializer, BuildSettings buildSettings)
 {
     Tracer.VerifyNonNullArgument(serializer, "serializer");
     Tracer.VerifyNonNullArgument(buildSettings, "buildSettings");
     this.serializer    = serializer;
     this.buildSettings = buildSettings;
 }
Example #3
0
        //==========================================================================================
        // Methods
        //==========================================================================================

        /// <summary>
        /// Copies the attached project and all of its referenced files to the destination directory.
        /// </summary>
        /// <param name="destinationPath">The destination path where the project file will be copied to.</param>
        /// <returns>A copy of the attached project rooted at <paramref name="destinationDirectory"/> or null if there were errors.</returns>
        public Project CopyTo(string destinationPath)
        {
            Tracer.VerifyStringArgument(destinationPath, "destinationPath");

            bool successful;

            // Reference the attached project.
            Project sourceProject = this.Project;

            // Create the destination project and a new project serializer for it.
            ProjectSerializer destSerializer = (ProjectSerializer)this.MemberwiseClone();
            Project           destProject    = this.CreateProject(destSerializer);

            // We have to have a back pointer from the serializer to the project otherwise when we go to
            // save the destination project, we'll have a null project pointer.
            destSerializer.project = destProject;

            // Set the destination project's properties.
            destProject.ProjectGuid = sourceProject.ProjectGuid;
            destProject.FilePath    = destinationPath;
            string destDirectory = Path.GetDirectoryName(destProject.FilePath);

            // Create the destination directory if it doesn't already exist.
            if (!Directory.Exists(destDirectory))
            {
                Directory.CreateDirectory(destDirectory);
            }

            // Copy the build settings.
            destProject.BuildSettings = (BuildSettings)sourceProject.BuildSettings.Clone();

            // Copy all of the configurations.
            destProject.ConfigurationProvider = sourceProject.ConfigurationProvider.Clone(destProject);

            // Loop through the files, copying each file to the destination directory.
            // TODO: Change the relative path of linked files.
            successful = this.CopyNodeFiles(sourceProject.RootNode, destProject, destProject.RootNode);

            // Loop through the references, adding them to the project.
            if (successful)
            {
                foreach (ReferenceFileNode referenceFile in sourceProject.ReferencesNode.Children)
                {
                    destProject.AddReference(referenceFile.AbsolutePath, false);
                }
            }

            // Now save the destination project.
            if (successful)
            {
                successful = destProject.Serializer.Save();
            }

            return(successful ? destProject : null);
        }
Example #4
0
        //==========================================================================================
        // Constructors
        //==========================================================================================

        /// <summary>
        /// Initializes a new instance of the <see cref="Project"/> class.
        /// </summary>
        /// <param name="serializer">The serializer to use for saving the project.</param>
        public Project(ProjectSerializer serializer) : this(serializer, new BuildSettings())
        {
        }
Example #5
0
        int IVsProjectFactory.CreateProject(string pszFilename, string pszLocation, string pszName, uint grfCreateFlags, ref Guid iidProject, out IntPtr ppvProject, out int pfCanceled)
        {
            IntPtr pUnk = IntPtr.Zero;

            pfCanceled = 0;
            ppvProject = IntPtr.Zero;

            bool loadedSuccessfully = false;

            try
            {
                Tracer.VerifyStringArgument(pszFilename, "pszFilename");

                __VSCREATEPROJFLAGS createFlags = (__VSCREATEPROJFLAGS)grfCreateFlags;

                // Get the right version of the project serializer.
                ProjectSerializer serializer = this.CreateSerializer(pszFilename);

                // Do we need to suppress any load failures from being reported to the end user.
                serializer.SilentFailures = ((createFlags & __VSCREATEPROJFLAGS.CPF_SILENT) == __VSCREATEPROJFLAGS.CPF_SILENT);

                // Now we need to load the project, either from a template file or from an existing file.
                bool openExisting     = ((createFlags & __VSCREATEPROJFLAGS.CPF_OPENFILE) == __VSCREATEPROJFLAGS.CPF_OPENFILE);
                bool openFromTemplate = ((createFlags & __VSCREATEPROJFLAGS.CPF_CLONEFILE) == __VSCREATEPROJFLAGS.CPF_CLONEFILE);
                Tracer.Assert((openExisting && !openFromTemplate) || (!openExisting && openFromTemplate), "The grfCreateFlags are incorrect. You can't have both opening existing and opening from template. Flags={0}", createFlags);

                if (openExisting)
                {
                    Tracer.WriteLineInformation(classType, "IVsProjectFactory.CreateProject", "Attempting to load project: File name={0} Location={1} Name={2} GUID={3}.", pszFilename, pszLocation, pszName, iidProject.ToString("B").ToUpper(CultureInfo.InvariantCulture));
                    loadedSuccessfully = serializer.Load(pszFilename);

                    if (loadedSuccessfully)
                    {
                        Tracer.WriteLineInformation(classType, "IVsProjectFactory.CreateProject", "Successfully loaded project '{0}'.", pszFilename);
                    }
                    else
                    {
                        Tracer.WriteLineInformation(classType, "IVsProjectFactory.CreateProject", "There were errors in loading project '{0}'.", pszFilename);
                    }
                }
                else
                {
                    Tracer.WriteLineInformation(classType, "IVsProjectFactory.CreateProject", "Attempting to create a new project from a template: File name={0} Location={1} Name={2} GUID={3}.", pszFilename, pszLocation, pszName, iidProject.ToString("B").ToUpper(CultureInfo.InvariantCulture));
                    Tracer.VerifyStringArgument(pszLocation, "pszLocation");
                    Tracer.VerifyStringArgument(pszName, "pszName");

                    string destinationFile = Path.Combine(pszLocation, pszName);
                    loadedSuccessfully = serializer.LoadFromTemplate(pszFilename, destinationFile);

                    if (loadedSuccessfully)
                    {
                        Tracer.WriteLineInformation(classType, "IVsProjectFactory.CreateProject", "Successfully loaded project '{0}'.", pszFilename);
                    }
                    else
                    {
                        Tracer.WriteLineInformation(classType, "IVsProjectFactory.CreateProject", "There were errors in loading project '{0}'.", pszFilename);
                    }
                }

                if (loadedSuccessfully)
                {
                    // Once we've loaded the project, we need to return the COM object that the environment is requesting.
                    pUnk = Marshal.GetIUnknownForObject(serializer.Project);
                    int hr = Marshal.QueryInterface(pUnk, ref iidProject, out ppvProject);
                    Tracer.Assert(NativeMethods.Succeeded(hr), "Cannot get the requested project interface ({0}): returned {1}", iidProject.ToString("B").ToUpper(CultureInfo.InvariantCulture), hr);
                    NativeMethods.ThrowOnFailure(hr);
                }
            }
            catch (Exception e)
            {
                Package.Instance.Context.NotifyInternalError(e.ToString());
            }
            finally
            {
                if (pUnk != IntPtr.Zero)
                {
                    Marshal.Release(pUnk);
                }
            }

            return(loadedSuccessfully ? NativeMethods.S_OK : NativeMethods.E_FAIL);
        }
 /// <summary>
 /// Gives subclasses a chance to create a type-specific project.
 /// </summary>
 /// <param name="serializer">The <see cref="ProjectSerializer"/> to use for saving the project.</param>
 /// <returns>A new <see cref="Project"/> object.</returns>
 protected virtual Project CreateProject(ProjectSerializer serializer)
 {
     return new Project(serializer);
 }
 //==========================================================================================
 // Methods
 //==========================================================================================
 /// <summary>
 /// Creates a new <see cref="WixProject"/> object.
 /// </summary>
 /// <param name="serializer">The <see cref="ProjectSerializer"/> to use for saving the project.</param>
 /// <returns>A new <see cref="Project"/> object.</returns>
 protected override Project CreateProject(ProjectSerializer serializer)
 {
     Tracer.Assert(serializer is WixProjectSerializer, "Somehow we're not getting the right type of serializer here.");
     return new WixProject((WixProjectSerializer)serializer);
 }
Example #8
0
 /// <summary>
 /// Gives subclasses a chance to create a type-specific project.
 /// </summary>
 /// <param name="serializer">The <see cref="ProjectSerializer"/> to use for saving the project.</param>
 /// <returns>A new <see cref="Project"/> object.</returns>
 protected virtual Project CreateProject(ProjectSerializer serializer)
 {
     return(new Project(serializer));
 }
Example #9
0
		//==========================================================================================
		// Constructors
		//==========================================================================================

		/// <summary>
		/// Initializes a new instance of the <see cref="Project"/> class.
		/// </summary>
		/// <param name="serializer">The serializer to use for saving the project.</param>
		public Project(ProjectSerializer serializer) : this(serializer, new BuildSettings())
		{
		}