Exemple #1
0
 public CSharpCompile(BuildGraph buildGraph, CSharpCompileParams p)
     : base(buildGraph)
 {
     m_params = p.Canonicalize();
 }
 public static CSharpCompileParams Canonicalize(this CSharpCompileParams p)
 {
     CSharpCompileParams o = new CSharpCompileParams();
     //-- Meta Options
     if (String.IsNullOrEmpty(p.CompileDir)) {
         throw new InvalidOperationException("C# CompileDir not specified");
     }
     o.CompileDir = QRPath.GetCanonical(p.CompileDir);
     o.BuildFileDir = String.IsNullOrEmpty(p.BuildFileDir)
         ? p.CompileDir
         : QRPath.GetCanonical(p.BuildFileDir);
     if (String.IsNullOrEmpty(p.FrameworkVersion)) {
         throw new InvalidOperationException("C# FrameworkVersion not specified");
     }
     o.FrameworkVersion = p.FrameworkVersion;
     o.ExtraArgs = p.ExtraArgs;
     //-- Input Options
     if (p.Sources.Count == 0) {
         throw new InvalidOperationException("C# Sources not specified");
     }
     foreach (string path in p.Sources) {
         string absPath = QRPath.GetAbsolutePath(path, p.CompileDir);
         o.Sources.Add(absPath);
     }
     foreach (string path in p.AssemblyReferences) {
         string absPath = QRPath.GetAbsolutePath(path, p.CompileDir);
         o.AssemblyReferences.Add(absPath);
     }
     foreach (string path in p.InputModules) {
         string absPath = QRPath.GetAbsolutePath(path, p.CompileDir);
         o.InputModules.Add(absPath);
     }
     //-- Output Options
     if (String.IsNullOrEmpty(p.OutputFilePath)) {
         throw new InvalidOperationException("C# compile OutputFilePath not specified");
     }
     o.OutputFilePath = QRPath.GetAbsolutePath(p.OutputFilePath, p.CompileDir);
     o.TargetFormat = p.TargetFormat;
     o.Platform = p.Platform;
     //-- Code Generation
     o.Debug = p.Debug;
     o.Optimize = p.Optimize;
     //-- Errors and Warnings
     o.WarnAsError = p.WarnAsError;
     o.WarnLevel = p.WarnLevel;
     //-- Language
     o.Checked = p.Checked;
     o.Unsafe = p.Unsafe;
     o.Defines.AddRange(p.Defines);
     o.LanguageVersion = p.LanguageVersion;
     //-- Miscellaneous
     o.NoConfig = p.NoConfig;
     //-- Advanced
     o.MainType = p.MainType;
     o.FullPaths = p.FullPaths;
     if (p.Debug) {
         o.PdbFilePath = QRPath.ComputeDefaultFilePath(p.PdbFilePath, o.OutputFilePath, ".pdb", o.CompileDir);
     }
     o.ModuleAssemblyName = p.ModuleAssemblyName;
     return o;
 }
Exemple #3
0
        private string CompileOrClean(string filePath)
        {
            BuildGraph buildGraph = new BuildGraph();
            var cscp = new CSharpCompileParams();
            cscp.BuildFileDir = Path.Combine(m_currentDir, m_outputDir);
            cscp.Sources.Add(filePath);
            cscp.OutputFilePath =
                Path.Combine(cscp.BuildFileDir, Path.GetFileName(filePath)) + ".dll";
            cscp.TargetFormat = CSharpTargetFormats.Library;
            cscp.FrameworkVersion = CSharpFrameworkVersion.V3_5;
            cscp.CompileDir = m_currentDir;
            cscp.Debug = true;
            cscp.Platform = CSharpPlatforms.AnyCpu;
            foreach (Assembly assembly in UsingAssemblies) {
                if (assembly != null) {
                    cscp.AssemblyReferences.Add(assembly.Location);
                }
            }
            var csc = new CSharpCompile(buildGraph, cscp);

            BuildOptions options = new BuildOptions();
            options.FileDecider = new FileSizeDateDecider();
            options.RemoveEmptyDirectories = true;

            var targets = new [] { cscp.OutputFilePath };
            BuildAction buildAction = m_wipe ? BuildAction.Clean : BuildAction.Build;
            BuildResults results = buildGraph.Execute(
                buildAction,
                options,
                targets,
                true);

            if (!results.Success) {
                throw new InvalidOperationException();
            }

            return cscp.OutputFilePath;
        }
Exemple #4
0
        static void TestCscCompile()
        {
            var cscp = new CSharpCompileParams();
            cscp.CompileDir = @"K:\work\code\C#\foo";
            string sourceFile = @"K:\work\code\C#\foo\Blah.cs";
            cscp.Sources.Add(sourceFile);
            cscp.OutputFilePath = QRPath.ChangeExtension(sourceFile, ".exe");
            cscp.FrameworkVersion = "v3.5";
            cscp.Platform = CSharpPlatforms.AnyCpu;
            cscp.Debug = true;

            var buildGraph = new BuildGraph();

            var csc = new CSharpCompile(buildGraph, cscp);
            csc.Execute();

            csc.UpdateExplicitIO();
            csc.UpdateImplicitInputs();

            string depsCache = DependencyCache.CreateDepsCacheString(csc, new FileSizeDateDecider());
            File.WriteAllText(csc.BuildFileBaseName + "__qr__.deps", depsCache);
        }