Exemplo n.º 1
0
        public void AddProject(ProjectReference project)
        {
            var sourceDir = project.SourceDir ?? _sourceDir;
            var targetDir = project.TargetDir ?? _targetDir;

            if (!System.IO.File.Exists(project.ProjectPath))
            {
                throw new Exception($"Project '{project.ProjectPath}' not found.");
            }


            var output     = Path.Combine(_project.OutDir, Path.ChangeExtension(Path.GetFileName(project.ProjectPath), "wxs"));
            var projectDir = Path.GetDirectoryName(project.ProjectPath);

            var args = new[] {
                $"project {project.ProjectPath}",
                project.Binaries ? "-pog Binaries" : "",
                project.Content ? "-pog Content" : "",
                project.Satellites ? "-pog Satellites" : "",
                "-ag", "-sfrag",
                $"-directoryid {targetDir}",
                "-template fragment",
                $"-platform AnyCPU",
                $"-projectname {project.Name}",
                $"-out {output}"
            };

            var pi = new ProcessStartInfo
            {
                FileName               = _heat,
                Arguments              = string.Join(" ", args),
                CreateNoWindow         = true,
                UseShellExecute        = false,
                RedirectStandardOutput = true
            };

            using (var p = Process.Start(pi))
            {
                p.WaitForExit();
                if (p.ExitCode != 0)
                {
                    throw new Exception(p.StandardOutput.ReadToEnd());
                }
            }

            var xml = XDocument.Load(output);

            foreach (var fragment in xml.Root.Elements())
            {
                _project.AddXml("Wix", fragment.ToString());
            }

            _project.CandleOptions +=
                $" -d\"{project.Name}.TargetDir\"={sourceDir} " + //As intended the TargetDir for candle is the sourceDir
                $" -d\"{project.Name}.ProjectDir\"={projectDir} ";
            _components.Add(project);

            if (!Compiler.PreserveTempFiles)
            {
                System.IO.File.Delete(output);
            }
        }