Пример #1
0
        private static void Build(Settings settings, Log log)
        {
            var properties = ProjectPropertiesHelpers.InitializeProperties(settings, log);

            if (properties.Sources.Count == 0)
            {
                Console.WriteLine("no sources found");
                return;
            }

            if (!Directory.Exists(properties.OutputDirectory))
            {
                Directory.CreateDirectory(properties.OutputDirectory);
            }

            if (!Directory.Exists(properties.ToolsDirectory))
            {
                Directory.CreateDirectory(properties.ToolsDirectory);
            }

            if (!Directory.Exists(properties.PackagesDirectory))
            {
                Directory.CreateDirectory(properties.PackagesDirectory);
            }

            if (!NugetAction.GetNugetAndRestore(properties, log))
            {
                return;
            }

            if (!GetDependencies(properties, log))
            {
                log.WriteLine("Unable to get dependencies from the project.lock.json file.");
            }

            if (!CscAction.Execute(properties, Log)) return;
            if (Settings.Target != "library")
            {
                ConvertToCoreConsoleAction(properties);
            }
            OutputRuntimeDependenciesAction(properties, log);
            Console.WriteLine("bin\\{0} created", properties.AssemblyNameAndExtension);
        }
Пример #2
0
 internal static void Clean(Settings settings, Log log)
 {
     var previous = log.IsEnabled;
     log.IsEnabled = false;
     var properties = ProjectPropertiesHelpers.InitializeProperties(settings, log);
     log.IsEnabled = previous;
     try
     {
         if (Directory.Exists(properties.ToolsDirectory))
             Directory.Delete(properties.ToolsDirectory, true);
         if (Directory.Exists(properties.OutputDirectory))
             Directory.Delete(properties.OutputDirectory, true);
         if (Directory.Exists(properties.PackagesDirectory))
             Directory.Delete(properties.PackagesDirectory, true);
     }
     catch (Exception e)
     {
         Console.WriteLine("Exception during cleanup: {0}", e.Message);
     }
 }
        public static ProjectProperties InitializeProperties(Settings settings, Log log)
        {
            // General Properites
            var properties = new ProjectProperties();
            var currentDirectory = Directory.GetCurrentDirectory();

            var buildDll = settings.Target == "library";

            properties.ProjectDirectory = Path.Combine(currentDirectory);
            properties.PackagesDirectory = Path.Combine(properties.ProjectDirectory, "packages");
            properties.OutputDirectory = Path.Combine(properties.ProjectDirectory, "bin");
            properties.ToolsDirectory = Path.Combine(properties.ProjectDirectory, "tools");
            properties.AssemblyName = Path.GetFileName(properties.ProjectDirectory);
            properties.OutputType = buildDll ? ".dll" : (settings.Runtime.StartsWith("ubuntu") || settings.Runtime.StartsWith("linux")) ? "" : ".exe";
            properties.Target = "DNXCore,Version=v5.0";
            properties.RuntimeIdentifier = settings.Runtime;
            FindCompiler(properties);

            AddToListWithoutDuplicates(properties.Sources, ParseProjectFile(properties, settings.ProjectFile, "Compile"));

            foreach (var file in settings.SourceFiles.Where(f => !f.StartsWith(properties.PackagesDirectory) && !f.StartsWith(properties.OutputDirectory) &&
                                                              !f.StartsWith(properties.ToolsDirectory)))
            {
                AddToListWithoutDuplicates(properties.Sources, file);
            }

            if (!string.IsNullOrWhiteSpace(settings.Recurse) && settings.Recurse != "*.cs")
            {
                AddToListWithoutDuplicates(properties.Sources,
                    Directory.GetFiles(properties.ProjectDirectory, settings.Recurse, SearchOption.AllDirectories));
            }

            if (properties.Sources.Count == 1)
            {
                properties.AssemblyName = Path.GetFileNameWithoutExtension(properties.Sources[0]);
            }

            var platformOptionSpecicifcation = GetPlatformOption(settings.Platform);

            // The anycpu32bitpreferred setting is valid only for executable (.EXE) files
            if (!(settings.Platform == "anycpu32bitpreferred" && buildDll))
                properties.CscOptions.Add("/platform:" + settings.Platform);

            // Packages
            properties.Packages.Add(@"""Microsoft.NETCore"": ""5.0.1-beta-23505""");
            properties.Packages.Add(@"""System.Console"": ""4.0.0-beta-23505""");

            properties.Packages.Add(@"""System.Text.Formatting"": ""0.1.0-d103015-1""");
            properties.Packages.Add(@"""System.Slices"": ""0.1.0-d103015-1""");
            properties.Packages.Add(@"""System.Buffers"": ""0.1.0-d103015-1""");

            properties.Packages.Add(@"""Microsoft.NETCore.ConsoleHost"": ""1.0.0-beta-23505""");
            properties.Packages.Add(@"""Microsoft.NETCore.Runtime"": ""1.0.1-beta-23505""");

            // add explicit references
            if (settings.References != null)
            {
                properties.References.AddRange(settings.References);
            }

            // CSC OPTIONS
            properties.CscOptions.Add("/nostdlib");
            properties.CscOptions.Add("/noconfig");
            if (settings.Unsafe)
            {
                properties.CscOptions.Add("/unsafe");
            }

            if (settings.Optimize)
            {
                properties.CscOptions.Add("/optimize");
            }

            if (!string.IsNullOrWhiteSpace(settings.Debug))
            {
                properties.CscOptions.Add("/debug:" + settings.Debug);
            }

            properties.CscOptions.Add("/target:" + settings.Target);

            LogProperties(log, properties, "Initialized Properties Log:", buildDll);

            AddToListWithoutDuplicates(properties.Packages, ParseProjectFile(properties, settings.ProjectFile, "Package"));

            LogProperties(log, properties, "Adjusted Properties Log:", buildDll);

            return properties;
        }
Пример #4
0
        public static ProjectProperties InitializeProperties(Settings settings, Log log)
        {
            // General Properites
            var properties = new ProjectProperties();
            var currentDirectory = Directory.GetCurrentDirectory();

            var buildDll = settings.Target == "library";

            properties.ProjectDirectory = Path.Combine(currentDirectory);
            properties.PackagesDirectory = Path.Combine(properties.ProjectDirectory, "packages");
            properties.OutputDirectory = Path.Combine(properties.ProjectDirectory, "bin");
            properties.ToolsDirectory = Path.Combine(properties.ProjectDirectory, "tools");
            properties.AssemblyName = Path.GetFileName(properties.ProjectDirectory);
            properties.OutputType = buildDll ? ".dll" : ".exe";
            FindCompiler(properties);

            AddToListWithoutDuplicates(properties.Sources, ParseProjectFile(properties, settings.ProjectFile, "Compile"));

            foreach (var file in settings.SourceFiles.Where(f => !f.StartsWith(properties.PackagesDirectory) && !f.StartsWith(properties.OutputDirectory) &&
                                                              !f.StartsWith(properties.ToolsDirectory)))
            {
                AddToListWithoutDuplicates(properties.Sources, file);
            }

            if (!string.IsNullOrWhiteSpace(settings.Recurse) && settings.Recurse != "*.cs")
            {
                AddToListWithoutDuplicates(properties.Sources,
                    Directory.GetFiles(properties.ProjectDirectory, settings.Recurse, SearchOption.AllDirectories));
            }

            if (properties.Sources.Count == 1)
            {
                properties.AssemblyName = Path.GetFileNameWithoutExtension(properties.Sources[0]);
            }

            var platformOptionSpecicifcation = GetPlatformOption(settings.Platform);

            // The anycpu32bitpreferred setting is valid only for executable (.EXE) files
            if (!(settings.Platform == "anycpu32bitpreferred" && buildDll))
                properties.CscOptions.Add("/platform:" + settings.Platform);

            // Packages
            properties.Packages.Add(@"""Microsoft.NETCore"": ""5.0.0""");
            properties.Packages.Add(@"""System.Console"": ""4.0.0-beta-23123""");
            //properties.Packages.Add(@"""Microsoft.NETCore.Console"": ""1.0.0-beta-*""");
            properties.Packages.Add(GetConsoleHost(platformOptionSpecicifcation));
            properties.Packages.Add(GetRuntimeCoreClr(platformOptionSpecicifcation));

            // References
            properties.References.Add(Path.Combine(properties.PackagesDirectory,
                @"System.Runtime\4.0.20\ref\dotnet\System.Runtime.dll"));
            properties.References.Add(Path.Combine(properties.PackagesDirectory,
                @"System.Console\4.0.0-beta-23123\ref\dotnet\System.Console.dll"));

            // Runtime Dependencies
            properties.Dependencies.Add(Path.Combine(properties.PackagesDirectory,
                GetRuntimeCoreClrDependencyNative(platformOptionSpecicifcation, "win7")));
            properties.Dependencies.Add(Path.Combine(properties.PackagesDirectory,
                GetRuntimeCoreClrDependencyLibrary(platformOptionSpecicifcation, "win7")));

            properties.Dependencies.Add(Path.Combine(properties.PackagesDirectory,
                @"System.Runtime\4.0.20\lib\netcore50"));
            properties.Dependencies.Add(Path.Combine(properties.PackagesDirectory,
                @"System.Console\4.0.0-beta-23123\lib\DNXCore50"));
            properties.Dependencies.Add(Path.Combine(properties.PackagesDirectory, @"System.IO\4.0.10\lib\netcore50"));
            properties.Dependencies.Add(Path.Combine(properties.PackagesDirectory,
                @"System.Threading\4.0.10\lib\netcore50"));
            properties.Dependencies.Add(Path.Combine(properties.PackagesDirectory,
                @"System.IO.FileSystem.Primitives\4.0.0\lib\dotnet"));
            properties.Dependencies.Add(Path.Combine(properties.PackagesDirectory,
                @"System.Text.Encoding\4.0.10\lib\netcore50"));
            properties.Dependencies.Add(Path.Combine(properties.PackagesDirectory,
                @"System.Threading.Tasks\4.0.10\lib\netcore50"));
            properties.Dependencies.Add(Path.Combine(properties.PackagesDirectory,
                @"System.Text.Encoding.Extensions\4.0.10\lib\netcore50"));
            properties.Dependencies.Add(Path.Combine(properties.PackagesDirectory,
                @"System.Runtime.InteropServices\4.0.20\lib\netcore50"));

            // CSC OPTIONS
            properties.CscOptions.Add("/nostdlib");
            properties.CscOptions.Add("/noconfig");
            if (settings.Unsafe)
            {
                properties.CscOptions.Add("/unsafe");
            }

            if (settings.Optimize)
            {
                properties.CscOptions.Add("/optimize");
            }

            if (!string.IsNullOrWhiteSpace(settings.Debug))
            {
                properties.CscOptions.Add("/debug:" + settings.Debug);
            }

            properties.CscOptions.Add("/target:" + settings.Target);

            LogProperties(log, properties, "Initialized Properties Log:", buildDll);

            Adjust(properties, Path.Combine(properties.ProjectDirectory, "dependencies.txt"), properties.Dependencies);
            Adjust(properties, Path.Combine(properties.ProjectDirectory, "references.txt"), properties.References);
            AddToListWithoutDuplicates(properties.Packages, ParseProjectFile(properties, settings.ProjectFile, "Package"));

            LogProperties(log, properties, "Adjusted Properties Log:", buildDll);

            return properties;
        }