예제 #1
0
        public CompileResult Compile(AmmyProject project, bool generateMetaFile = false, bool needBamlGeneration = false, bool needUpdate = true, bool needXamlGeneration = true)
        {
            var compileResult = new CompileResult(needBamlGeneration)
            {
                AmmyProject = project
            };

            if (project.ProjectSupport == null)
            {
                return(compileResult);
            }

            try {
                if (project.MissingFiles.Count > 0)
                {
                    foreach (var missingFile in project.MissingFiles)
                    {
                        compileResult.AddError(missingFile + " does not exist.");
                    }

                    return(compileResult);
                }

                foreach (var file in project.Files)
                {
                    compileResult.Files.Add(file);
                }

                compileResult.CompilationData = project.RefreshReferences();

                project.Context.ProjectDir        = project.FsProject.ProjectDir;
                project.Context.SourceCodeProject = project.CSharpProject;
                project.Context.NeedUpdate        = project.Platform.SupportsRuntimeUpdate && needUpdate;

                project.RefreshProject(project.OutputPath, project.RootNamespace, project.AssemblyName);

                EnsureOutputDirectoryExists(project.OutputPath.ToAbsolutePath(project.FsProject.ProjectDir));

                var anyErrors    = compileResult.CompilerMessages.Any(msg => msg.Type == CompilerMessageType.Error || msg.Type == CompilerMessageType.FatalError);
                var bamlCompiler = new BamlCompiler(_isMsBuildCompilation);

                if (!anyErrors)
                {
                    if (needXamlGeneration)
                    {
                        GenerateXamlFiles(compileResult, generateMetaFile);
                    }

                    if (needBamlGeneration)
                    {
                        bamlCompiler.CompileBamlFiles(compileResult, project);
                    }
                }
            } catch (Exception e) {
                compileResult.AddError("Ammy compilation error: " + e);
            }

            return(compileResult);
        }
예제 #2
0
        public void CompileBamlFiles(CompileResult result, AmmyProject project)
        {
            var directory = Path.GetDirectoryName(GetType().Assembly.Location);
            var markup    = string.Join(",", result.GeneratedXamlFiles.SelectMany(f => new[] { "\"" + f + "\"" }));

            var references    = string.Join(",", project.References.SelectMany(r => new[] { "\"" + r.Path + "\"" }));
            var outputPath    = project.OutputPath.TrimEnd('\\');
            var assemblyName  = project.AssemblyName;
            var rootNamespace = project.RootNamespace;
            var projectDir    = project.FsProject.ProjectDir;
            var sources       = string.Join(",", project.CSharpProject.GetFilenames());
            var targetPath    = project.TargetPath;
            var args          = $"/targetPath:{targetPath} /assemblyName:{assemblyName} /rootNamespace:{rootNamespace} /outputPath:\"{outputPath}\" /markup:{markup} /references:{references} /sources:{sources}";
            var tempFileName  = Path.GetTempFileName();

            File.WriteAllText(tempFileName, args);

            var process = new Process {
                StartInfo = new ProcessStartInfo {
                    FileName               = Path.Combine(directory, "bamlcwpf.exe"),
                    Arguments              = tempFileName,
                    UseShellExecute        = false,
                    RedirectStandardOutput = true,
                    RedirectStandardError  = true,
                    CreateNoWindow         = true,
                    WorkingDirectory       = projectDir
                }
            };

            process.Start();

            ParseOutput(result, projectDir, process);

            process.WaitForExit();

            try {
                File.Delete(tempFileName);
            } catch { }
        }