Example #1
0
        private void AddFile(string fileName, ProjectEx project, WiXDirectory projectDirectory, Component component, Hashtable componentFiles)
        {
            string fullPath = project.GetFullPath(fileName);

            WiXDirectory fileParent = null;
            // If we have any project sub folders add them now.
            string addDirPath = Path.GetDirectoryName(fileName);

            fileParent = AddFolder(
                projectDirectory,
                component,
                addDirPath);

            WiXFile wixFile = null;

            if (componentFiles.ContainsKey(fullPath))
            {
                wixFile = componentFiles[fullPath] as WiXFile;
            }
            else
            {
                wixFile = new WiXFile(component, fullPath);
                componentFiles.Add(fullPath, wixFile);
            }

            // Have WiX copy the file to the final destination
            wixFile.CopyFile(fileParent.Id, Path.GetFileName(fileName));
        }
Example #2
0
 public Shortcut(File file, string name, DirectoryRef directory)
     : this((WiXElement)file, name, directory)
 {     
 }
Example #3
0
 public Shortcut(Component component, File target, string name, DirectoryRef directory)
     : this(component, (WiXElement)target, name, directory)
 {
 }
Example #4
0
        public void Save(
            string slnFile,
            string wxsFile,
            Guid componentGuid)
        {
            base.Save(slnFile);
            this.Add(new SolutionObject(SolutionFile.CreateDotSln(slnFile)));

            Hashtable componentFiles = new Hashtable();

            solutionName = Path.GetFileNameWithoutExtension(slnFile);

            Fragment fragment = new Fragment("Fragment_" + solutionName);

            m_SolutionFragment = fragment;

            if (fragmentIncludeFiles != null)
            {
                foreach (ITaskItem fragmentInclude in fragmentIncludeFiles)
                {
                    fragment.PrependInclude(fragmentInclude.ItemSpec);
                }
            }

            DirectoryRef samplesRef = new DirectoryRef(fragment, parentDirectoryRef);

            WiXDirectory solutionDir = new WiXDirectory(samplesRef, solutionName);

            solutionDir.Id = solutionName + "_" + solutionDir.Id;

            DirectoryRef tempRef = new DirectoryRef(fragment, "TEMPFOLDERINSTALLDIR");

            WiXDirectory tempSlnDir = new WiXDirectory(tempRef, solutionName);

            tempSlnDir.Id = solutionName + "_" + tempSlnDir.Id;

            Component component = new Component(tempSlnDir,
                                                "Component_" + solutionName,
                                                componentGuid);

            if (shortcut == ShortcutType.FOLDER)
            {
                Shortcut folderShortcut = new Shortcut(
                    component,
                    solutionDir,
                    solutionName,
                    new DirectoryRef(fragment, "ProgramMenuDir"));

                folderShortcut.Id = solutionName + "_" + folderShortcut.Id;
            }

            foreach (SolutionObject slnObj in this)
            {
                if (slnObj.Object is ProjectEx)
                {
                    #region ProjectEx
                    ProjectEx project = slnObj.Object as ProjectEx;

                    // Add the project folder to the WiX file
                    string       projectFolderName = Path.GetFileNameWithoutExtension(project.FullFileName);
                    WiXDirectory projectDirectory  = new WiXDirectory(solutionDir, projectFolderName);
                    projectDirectory.Id = solutionName + "_" + projectDirectory.Id;
                    component.CreateFolder(projectDirectory);

                    WiXFile projectFile = new WiXFile(component, Path.Combine(Path.GetDirectoryName(wxsFile), Path.GetFileName(project.FullFileName)));
                    projectFile.CopyFile(projectDirectory.Id);

                    // Add subfolders
                    foreach (_BE.ProjectItem folderItem in project.MsBuildProject.GetItems("Folder"))
                    {
                        string addDirPath = folderItem.Xml.Include;
                        if (addDirPath.EndsWith(Path.DirectorySeparatorChar.ToString()))
                        {
                            addDirPath = addDirPath.Substring(0, addDirPath.Length - 1);
                        }

                        AddFolder(
                            projectDirectory,
                            component,
                            addDirPath);
                    }

                    // Loop through all known item groups that map to files
                    // and add those files.

                    foreach (string groupName in ProjectEx.FileGroups)
                    {
                        foreach (_BE.ProjectItem buildItem in project.MsBuildProject.GetItems(groupName))
                        {
                            AddFile(
                                buildItem.Xml.Include,
                                project,
                                projectDirectory,
                                component,
                                componentFiles);
                        }
                    }

                    foreach (string extraFile in project.ExtraFiles)
                    {
                        AddFile(
                            extraFile,
                            project,
                            projectDirectory,
                            component,
                            componentFiles);
                    }
                    #endregion
                }
                else
                {
                    #region SolutionFile
                    SolutionFile slnFileObj  = slnObj.Object as SolutionFile;
                    WiXFile      slnFileElem = new WiXFile(component, slnFileObj.File);
                    slnFileElem.Id = solutionName + "_" + slnFileElem.Id;
                    slnFileElem.CopyFile(solutionDir.Id);

                    if (slnFileObj.IsDotSln && shortcut == ShortcutType.DOTSLN)
                    {
                        Shortcut dotSlnShortcut = new Shortcut(
                            slnFileElem,
                            Path.GetFileNameWithoutExtension(slnFileElem.Name),
                            new DirectoryRef(fragment, "ProgramMenuDir"));

                        dotSlnShortcut.Id = solutionName + "_" + dotSlnShortcut.Id;
                    }
                    #endregion
                }
            }

            if (componentIncludeFiles != null)
            {
                foreach (ITaskItem componentInclude in componentIncludeFiles)
                {
                    component.AppendInclude(componentInclude.ItemSpec);
                }
            }

            fragment.Element.OwnerDocument.Save(wxsFile);
        }
Example #5
0
        public override bool Execute()
        {
            try
            {
                //
                // Do some setup
                //
                this.Log.LogMessage("Create Assembly Fragment Task");

                string assemblyRoot = Path.GetFileNameWithoutExtension(assemblyName);

                if (fragmentId == null)
                {
                    fragmentId = "Fragment" + assemblyEndian + assemblyName;
                }

                componentId = "Component" + assemblyEndian + assemblyName;

                //
                // Build WiX file
                //
                Fragment fragment = new Fragment(fragmentId);

                if (includeFiles != null)
                {
                    foreach (ITaskItem item in includeFiles)
                    {
                        if (item == null)
                        {
                            continue;
                        }
                        fragment.PrependInclude(item.ItemSpec);
                    }
                }

                DirectoryRef dirref = new DirectoryRef(
                    fragment,
                    directoryRef);


                Component fileComponent = null;

                // Create Component and add files
                if (componentGuid != Guid.Empty)
                {
                    // Generate new GUID for BE files, else BE files will be stranded upon uninstall
                    if (assemblyEndian == "_be_")
                    {
                        componentGuid = Guid.NewGuid();
                    }

                    fileComponent = new Component(
                        dirref,
                        componentId,
                        componentGuid);

                    fragment.PrependDefine(
                        string.Format("COMPONENTID=\"{0}\"", fileComponent.Id));

                    foreach (ITaskItem item in componentFiles)
                    {
                        if (item == null)
                        {
                            continue;
                        }
                        string fileName = item.ItemSpec;

                        string assemblyType = item.GetMetadata("AssemblyType");
                        assemblyType = String.IsNullOrEmpty(assemblyType) ? "" : assemblyType.ToLower();

                        if (assemblyType != "")
                        {
                            if (assemblyType != ".net" && assemblyType != "win32" && assemblyType != "no")
                            {
                                throw new ApplicationException("Invalid assemblyType \"" + assemblyType + "\" in file metadata ");
                            }
                        }

                        Microsoft.SPOT.WiX.File file = new Microsoft.SPOT.WiX.File(
                            fileComponent,
                            item.GetMetadata("Name"),
                            fileName,
                            false);

                        file.Id = file.Id + assemblyEndian;

                        fragment.PrependDefine(
                            string.Format("ID{0}=\"{1}\"", file.Name.Replace('.', '_'), file.Id));

                        if (!string.IsNullOrEmpty(assemblyShortcut) && fileName.ToLower().EndsWith(".exe"))
                        {
                            Shortcut sc = new Shortcut(file, assemblyShortcut, new DirectoryRef(fragment, "ProgramMenuDir"));
                        }
                    }

                    if (componentIncludeFiles != null)
                    {
                        foreach (ITaskItem item in componentIncludeFiles)
                        {
                            if (item == null)
                            {
                                continue;
                            }
                            fileComponent.AppendInclude(item.ItemSpec);
                        }
                    }
                }

                if (postIncludeFiles != null)
                {
                    foreach (ITaskItem item in postIncludeFiles)
                    {
                        if (item == null)
                        {
                            continue;
                        }
                        fragment.AppendInclude(item.ItemSpec);
                    }
                }

                // Save Fragment File
                string fragmentFileDirectory = Path.GetDirectoryName(fragmentFileName);

                if (!System.IO.Directory.Exists(fragmentFileDirectory))
                {
                    System.IO.Directory.CreateDirectory(fragmentFileDirectory);
                }

                fragment.Element.OwnerDocument.Save(fragmentFileName);

                return(true);
            }
            catch (Exception e)
            {
                this.Log.LogErrorFromException(e);
                return(false);
            }
        }
        public override bool Execute()
        {
            try
            {
                //
                // Do some setup
                //
                this.Log.LogMessage("Create Assembly Fragment Task");

                string assemblyRoot = Path.GetFileNameWithoutExtension(assemblyName);

                if (fragmentId == null)
                {
                    fragmentId = "Fragment" + assemblyEndian + assemblyName;
                }

                componentId = "Component" + assemblyEndian + assemblyName;

                //
                // Build WiX file
                //
                Fragment fragment = new Fragment(fragmentId);

                if (includeFiles != null)
                {
                    foreach (ITaskItem item in includeFiles)
                    {
                        if (item == null) continue;
                        fragment.PrependInclude(item.ItemSpec);
                    }
                }

                DirectoryRef dirref = new DirectoryRef(
                    fragment,
                    directoryRef);


                Component fileComponent = null;

                // Create Component and add files
                if (componentGuid != Guid.Empty)
                {
                    // Generate new GUID for BE files, else BE files will be stranded upon uninstall
                    if ( assemblyEndian == "_be_" )
                    {
                        componentGuid = Guid.NewGuid();
                    }
 
                    fileComponent = new Component(
                        dirref,
                        componentId,
                        componentGuid);

                    fragment.PrependDefine(
                        string.Format("COMPONENTID=\"{0}\"", fileComponent.Id));

                    foreach (ITaskItem item in componentFiles)
                    {
                        if (item == null) continue;
                        string fileName = item.ItemSpec;

                        string assemblyType = item.GetMetadata("AssemblyType");
                        assemblyType = String.IsNullOrEmpty(assemblyType) ? "" : assemblyType.ToLower();

                        if ( assemblyType != "" )
                        {
                            if ( assemblyType != ".net" && assemblyType != "win32" && assemblyType != "no" )
                            {
                                throw new ApplicationException("Invalid assemblyType \"" + assemblyType + "\" in file metadata ");
                            }
                        }

                        Microsoft.SPOT.WiX.File file = new Microsoft.SPOT.WiX.File(
                            fileComponent,
                            item.GetMetadata("Name"),
                            fileName,
                            false);

                        file.Id = file.Id + assemblyEndian;

                        fragment.PrependDefine(
                                string.Format("ID{0}=\"{1}\"", file.Name.Replace('.', '_'), file.Id));

                        if(!string.IsNullOrEmpty(assemblyShortcut) && fileName.ToLower().EndsWith(".exe"))
                        {
                            Shortcut sc = new Shortcut(file, assemblyShortcut, new DirectoryRef(fragment,"ProgramMenuDir"));
                        }
                    }

                    if (componentIncludeFiles != null)
                    {
                        foreach (ITaskItem item in componentIncludeFiles)
                        {
                            if (item == null) continue;
                            fileComponent.AppendInclude(item.ItemSpec);
                        }
                    }
                }

                if (postIncludeFiles != null)
                {
                    foreach (ITaskItem item in postIncludeFiles)
                    {
                        if (item == null) continue;
                        fragment.AppendInclude(item.ItemSpec);
                    }
                }

                // Save Fragment File
                string fragmentFileDirectory = Path.GetDirectoryName(fragmentFileName);

                if (!System.IO.Directory.Exists(fragmentFileDirectory))
                {
                    System.IO.Directory.CreateDirectory(fragmentFileDirectory);
                }

                fragment.Element.OwnerDocument.Save(fragmentFileName);

                return true;
            }
            catch (Exception e)
            {
                this.Log.LogErrorFromException(e);
                return false;
            }
        }