Beispiel #1
0
        public static bool GetNugetAndRestore(ProjectProperties properties, Log log)
        {
            var nugetFile = Path.Combine(properties.ToolsDirectory, "nuget.exe");
            var success = true;
            if (!File.Exists(nugetFile))
            {
                success = DownloadNugetAction(properties, nugetFile);
            }

            var projectJsonFile = Path.Combine(properties.ProjectDirectory, "project.json");
            if (!File.Exists(projectJsonFile))
            {
                projectJsonFile = Path.Combine(properties.ToolsDirectory, "project.json");
            }

            var nugetConfigFile = Path.Combine(properties.ProjectDirectory, "nuget.config");
            if (!File.Exists(nugetConfigFile))
            {
                nugetConfigFile = Path.Combine(properties.ToolsDirectory, "nuget.config");
            }

            if (!success || !RestorePackagesAction(properties, log, nugetFile, projectJsonFile, nugetConfigFile))
            {
                Console.WriteLine("Failed to get nuget or restore packages.");
                return false;
            }
            return true;
        }
Beispiel #2
0
        public static bool Execute(ProjectProperties properties, Log log)
        {
            Console.WriteLine("compiling");
            var processSettings = new ProcessStartInfo
            {
                FileName = properties.CscPath,
                Arguments = properties.FormatCscArguments()
            };

            log.WriteLine("Executing {0}", processSettings.FileName);
            log.WriteLine("Csc Arguments: {0}", processSettings.Arguments);

            processSettings.CreateNoWindow = true;
            processSettings.RedirectStandardOutput = true;
            processSettings.UseShellExecute = false;

            Process cscProcess;
            try
            {
                cscProcess = Process.Start(processSettings);
            }
            catch (Win32Exception)
            {
                Console.WriteLine("ERROR: csc.exe needs to be on the path.");
                return false;
            }

            if (cscProcess == null) return false;
            var output = cscProcess.StandardOutput.ReadToEnd();
            log.WriteLine(output);

            cscProcess.WaitForExit();

            return !output.Contains("error CS");
        }
Beispiel #3
0
        public static bool RestorePackagesAction(ProjectProperties properties, Log log, string nugetFile, string jsonFile)
        {
            Console.WriteLine("restoring packages");

            if (!File.Exists(nugetFile))
            {
                Console.WriteLine("Could not find file {0}.", nugetFile);
                return false;
            }

            if (!File.Exists(jsonFile))
            {
                Console.WriteLine("Could not find file {0}.", jsonFile);
                return false;
            }

            var processSettings = new ProcessStartInfo
            {
                FileName = nugetFile,
                Arguments =
                    "restore " + jsonFile + " -PackagesDirectory " + properties.PackagesDirectory + " -ConfigFile " +
                    Path.Combine(properties.ToolsDirectory, "nuget.config"),
                CreateNoWindow = true,
                UseShellExecute = false,
                RedirectStandardOutput = true,
                RedirectStandardError = true
            };

            log.WriteLine("Executing {0}", processSettings.FileName);
            log.WriteLine("Arguments: {0}", processSettings.Arguments);
            log.WriteLine("project.json:\n{0}", File.ReadAllText(jsonFile));

            using (var process = Process.Start(processSettings))
            {
                try
                {
                    if (process != null)
                    {
                        var output = process.StandardOutput.ReadToEnd();
                        var error = process.StandardError.ReadToEnd();
                        log.WriteLine(output);
                        log.Error(error);
                        process.WaitForExit();
                        var exitCode = process.ExitCode;
                        if (exitCode != 0) Console.WriteLine("Process exit code: {0}", exitCode);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    return false;
                }
            }
            return true;
        }
Beispiel #4
0
        private static void ConvertToCoreConsoleAction(ProjectProperties properties)
        {
            var dllPath = Path.ChangeExtension(properties.OutputAssemblyPath, "dll");
            if (File.Exists(dllPath))
            {
                File.Delete(dllPath);
            }
            File.Move(properties.OutputAssemblyPath, dllPath);

            var coreConsolePath = properties.Dependencies.FirstOrDefault(p => Path.GetFileNameWithoutExtension(p).Equals("coreconsole", StringComparison.OrdinalIgnoreCase));
            File.Copy(coreConsolePath, properties.OutputAssemblyPath);
        }
Beispiel #5
0
        private static void ConvertToCoreConsoleAction(ProjectProperties properties)
        {
            var dllPath = Path.ChangeExtension(properties.OutputAssemblyPath, "dll");
            if (File.Exists(dllPath))
            {
                File.Delete(dllPath);
            }
            File.Move(properties.OutputAssemblyPath, dllPath);

            var coreConsolePath =
                ProjectPropertiesHelpers.GetConsoleHostNative(ProjectPropertiesHelpers.GetPlatformOption(Settings.Platform), "win7") +
                "\\CoreConsole.exe";
            File.Copy(Path.Combine(properties.PackagesDirectory, coreConsolePath), properties.OutputAssemblyPath);
        }
Beispiel #6
0
        public static bool DownloadNugetAction(ProjectProperties properties, string nugetFile)
        {
            CreateDefaultProjectJson(properties);
            CreateNugetConfig(properties);

            var client = new HttpClient();
            var requestUri = new Uri(@"https://dist.nuget.org/win-x86-commandline/v3.2.1-rc/nuget.exe",
                UriKind.Absolute);

            var sourceStreamTask = client.GetStreamAsync(requestUri);
            try
            {
                sourceStreamTask.Wait();
            }
            catch (AggregateException exception)
            {
                foreach (var ex in exception.InnerExceptions)
                {
                    Console.WriteLine(ex.Message);
                    return false;
                }
            }

            using (var sourceStream = sourceStreamTask.Result)
            using (var destinationStream = new FileStream(nugetFile, FileMode.Create, FileAccess.Write))
            {
                var buffer = new byte[1024];
                while (true)
                {
                    var read = sourceStream.Read(buffer, 0, buffer.Length);
                    if (read < 1) break;
                    destinationStream.Write(buffer, 0, read);
                }
            }

            return true;
        }
Beispiel #7
0
        private static void CreateDefaultProjectJson(ProjectProperties properties)
        {
            var fileName = Path.Combine(properties.ToolsDirectory, "project.json");
            var fs = new FileStream(fileName, FileMode.Create);
            using (var file = new StreamWriter(fs, Encoding.UTF8))
            {
                file.WriteLine(@"{");
                file.WriteLine(@"    ""dependencies"": {");

                for (var index = 0; index < properties.Packages.Count; index++)
                {
                    var package = properties.Packages[index];
                    file.Write(@"        ");
                    file.Write(package);
                    if (index < properties.Packages.Count - 1)
                    {
                        file.WriteLine(",");
                    }
                    else
                    {
                        file.WriteLine();
                    }
                }
                file.WriteLine(@"    },");
                file.WriteLine(@"    ""frameworks"": {");
                file.WriteLine(@"        ""dnxcore50"": { }");
                file.WriteLine(@"    },");

                file.WriteLine(@"    ""runtimes"": {");
                file.WriteLine(@"        ""win7-x86"": { },");
                file.WriteLine(@"        ""win7-x64"": { },");
                file.WriteLine(@"        ""ubuntu.14.04-x64"": { }");
                file.WriteLine(@"    }");
                file.WriteLine(@"}");

            }
        }
 private static void Adjust(ProjectProperties properties, string adjustmentFilePath, ICollection<string> list)
 {
     if (!File.Exists(adjustmentFilePath)) return;
     foreach (var line in File.ReadAllLines(adjustmentFilePath))
     {
         if (string.IsNullOrWhiteSpace(line)) continue;
         if (line.StartsWith("//")) continue; // commented out line
         var adjustment = line.Substring(1).Trim();
         if (line.StartsWith("-"))
         {
             list.Remove(Path.Combine(properties.PackagesDirectory, adjustment));
         }
         else
         {
             list.Add(Path.Combine(properties.PackagesDirectory, adjustment));
         }
     }
 }
        private static void FindCompiler(ProjectProperties properties)
        {
            string cscEnvPath = Environment.GetEnvironmentVariable("CSCPATH");
            if (cscEnvPath != null)
            {
                string fullCscPath = Path.Combine(cscEnvPath, "csc.exe");
                if (File.Exists(fullCscPath))
                {
                    properties.CscPath = fullCscPath;
                    return;
                }
            }

            properties.CscPath = Path.Combine(properties.ToolsDirectory, "csc.exe");
            if (File.Exists(properties.CscPath))
            {
                return;
            }

            properties.CscPath = @"D:\git\roslyn\Binaries\Debug\core-clr\csc.exe";
            if (!File.Exists(properties.CscPath))
            {
                properties.CscPath = "csc.exe";
            }
        }
        private static void FindCompiler(ProjectProperties properties)
        {
            properties.CscPath = Path.Combine(properties.ToolsDirectory, "csc.exe");
            if (File.Exists(properties.CscPath))
            {
                return;
            }

            properties.CscPath = @"D:\git\roslyn\Binaries\Debug\core-clr\csc.exe";
            if (!File.Exists(properties.CscPath))
            {
                properties.CscPath = "csc.exe";
            }
        }
        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;
        }
Beispiel #12
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);
        }
Beispiel #13
0
        private static bool GetDependencies(ProjectProperties properties, Log log)
        {
            var projectLockFile = Path.Combine(properties.ProjectDirectory, "project.lock.json");

            if (!File.Exists(projectLockFile))
            {
                projectLockFile = Path.Combine(properties.ToolsDirectory, "project.lock.json");
            }

            var jsonString = File.ReadAllText(projectLockFile);
            var docJsonOutput = JsonConvert.DeserializeObject<ProjectLockJson>(jsonString);

            var target = properties.Target;
            if (!string.IsNullOrEmpty(properties.RuntimeIdentifier))
            {
                target += "/" + properties.RuntimeIdentifier;
            }
            Dictionary<string, Target> packages;
            docJsonOutput.Targets.TryGetValue(target, out packages);
            if (packages == null)
            {
                log.Error("Packages for the specified target not found {0}.", properties.Target);
                return false;
            }

            var references = new List<string>();
            var dependencies = new List<string>();

            foreach (var package in packages)
            {
                if (package.Value.Compile != null)
                {
                    var compileKeys = package.Value.Compile.Keys;
                    if (compileKeys.Count != 0)
                    {
                        references.AddRange(
                            compileKeys.Select(
                                key => properties.ProjectDirectory + "/packages/" + package.Key + "/" + key));
                    }
                }

                if (package.Value.Native != null)
                {
                    var nativeKeys = package.Value.Native.Keys;
                    if (nativeKeys.Count != 0)
                    {
                        dependencies.AddRange(
                            nativeKeys.Select(
                                key => properties.ProjectDirectory + "/packages/" + package.Key + "/" + key));
                    }
                }

                if (package.Value.Runtime != null)
                {
                    var runtimeKeys = package.Value.Runtime.Keys;
                    if (runtimeKeys.Count != 0)
                    {
                        dependencies.AddRange(
                            runtimeKeys.Select(
                                key => properties.ProjectDirectory + "/packages/" + package.Key + "/" + key));
                    }
                }
            }

            references.RemoveAll(x => x.EndsWith("_._"));

            foreach (var reference in references)
            {
                properties.References.Add(Path.Combine(properties.PackagesDirectory, reference));
            }
            foreach (var outputAssembly in dependencies)
            {
                properties.Dependencies.Add(outputAssembly);
            }

            return true;
        }
Beispiel #14
0
 private static string FormatCscArguments(this ProjectProperties project)
 {
     return(project.FormatCscOptions() + project.FormatReferenceOption() + project.FormatSourcesOption());
 }
        private static List<string> ParseProjectFile(ProjectProperties properties, string projectFile,
            string elementName)
        {
            var attributes = GetAttributes(elementName);
            if (!File.Exists(projectFile) || attributes == null)
            {
                return new List<string>();
            }

            var attributeValues = new List<string>();
            using (var xmlReader = XmlReader.Create(projectFile))
            {
                xmlReader.MoveToContent();
                while (xmlReader.Read())
                {
                    if (xmlReader.NodeType == XmlNodeType.Element && xmlReader.Name == elementName)
                    {
                        attributeValues.AddRange(attributes.Select(attribute => xmlReader.GetAttribute(attribute)));
                    }
                }
            }

            List<string> values;
            switch (elementName)
            {
                case "Compile":
                    values = GetSourcesFromProjectFile(properties, attributeValues);
                    break;
                case "Package":
                    values = GetPackagesFromProjectFile(attributeValues);
                    break;
                default:
                    values = new List<string>();
                    break;
            }
            return values;
        }
 private static List<string> GetSourcesFromProjectFile(ProjectProperties properties,
     IEnumerable<string> attributeValues)
 {
     var sourceFiles = new List<string>();
     foreach (var val in attributeValues)
     {
         if (val == "*.cs")
         {
             sourceFiles.AddRange(Directory.GetFiles(properties.ProjectDirectory, "*.cs"));
         }
         else if (val.EndsWith("\\*.cs"))
         {
             sourceFiles.AddRange(
                 Directory.GetFiles(Path.Combine(properties.ProjectDirectory, val.Replace("\\*.cs", "")), "*.cs"));
         }
         else
         {
             sourceFiles.Add(Path.Combine(properties.ProjectDirectory, val));
         }
     }
     return sourceFiles;
 }
Beispiel #17
0
        private static bool GetDependencies(ProjectProperties properties, Log log)
        {
            var projectLockFile = Path.Combine(properties.ProjectDirectory, "project.lock.json");

            if (!File.Exists(projectLockFile))
            {
                projectLockFile = Path.Combine(properties.ToolsDirectory, "project.lock.json");
            }

            var jsonString    = File.ReadAllText(projectLockFile);
            var docJsonOutput = JsonConvert.DeserializeObject <ProjectLockJson>(jsonString);

            var target = properties.Target + "/" + properties.RuntimeIdentifier;
            Dictionary <string, Target> packages;

            docJsonOutput.Targets.TryGetValue(target, out packages);
            if (packages == null)
            {
                log.Error("Packages for the specified target not found {0}.", properties.Target);
                return(false);
            }

            var references   = new List <string>();
            var dependencies = new List <string>();

            foreach (var package in packages)
            {
                if (package.Value.Compile != null)
                {
                    var compileKeys = package.Value.Compile.Keys;
                    if (compileKeys.Count != 0)
                    {
                        references.AddRange(
                            compileKeys.Select(
                                key => properties.ProjectDirectory + "/packages/" + package.Key + "/" + key));
                    }
                }

                if (package.Value.Native != null)
                {
                    var nativeKeys = package.Value.Native.Keys;
                    if (nativeKeys.Count != 0)
                    {
                        dependencies.AddRange(
                            nativeKeys.Select(
                                key => properties.ProjectDirectory + "/packages/" + package.Key + "/" + key));
                    }
                }

                if (package.Value.Runtime != null)
                {
                    var runtimeKeys = package.Value.Runtime.Keys;
                    if (runtimeKeys.Count != 0)
                    {
                        dependencies.AddRange(
                            runtimeKeys.Select(
                                key => properties.ProjectDirectory + "/packages/" + package.Key + "/" + key));
                    }
                }
            }

            references.RemoveAll(x => x.EndsWith("_._"));

            foreach (var reference in references)
            {
                properties.References.Add(Path.Combine(properties.PackagesDirectory, reference));
            }
            foreach (var outputAssembly in dependencies)
            {
                properties.Dependencies.Add(outputAssembly);
            }

            return(true);
        }
Beispiel #18
0
        private static void CreateNugetConfig(ProjectProperties properties)
        {
            var fileName = Path.Combine(properties.ToolsDirectory, "nuget.config");
            var fs = new FileStream(fileName, FileMode.Create);
            using (var file = new StreamWriter(fs, Encoding.UTF8))
            {
                file.WriteLine(@"<?xml version = ""1.0"" encoding=""utf-8""?>");
                file.WriteLine(@"<configuration>");
                file.WriteLine(@"    <packageSources>");

                file.WriteLine(
                    @"        <add key = ""netcore-prototype"" value=""https://www.myget.org/F/netcore-package-prototyping""/>");
                file.WriteLine(
                    @"        <add key = ""nuget.org"" value = ""https://api.nuget.org/v3/index.json"" protocolVersion = ""3""/>");

                file.WriteLine(@"    </packageSources>");
                file.WriteLine(@"</configuration>");
            }
        }
        private static void LogProperties(this Log log, ProjectProperties project, string heading, bool buildDll)
        {
            if (!log.IsEnabled) return;

            log.WriteLine(heading);
            log.WriteLine("ProjectDirectory     {0}", project.ProjectDirectory);
            log.WriteLine("PackagesDirectory    {0}", project.PackagesDirectory);
            log.WriteLine("OutputDirectory      {0}", project.OutputDirectory);
            log.WriteLine("ToolsDirectory       {0}", project.ToolsDirectory);
            log.WriteLine(buildDll ? "LibraryFilename      {0}" : "ExecutableFilename   {0}", project.AssemblyName);
            log.WriteLine("csc.exe Path         {0}", project.CscPath);
            log.WriteLine("output path          {0}", project.OutputAssemblyPath);
            log.WriteList(project.Sources, "SOURCES");
            log.WriteList(project.Packages, "PACKAGES");
            log.WriteList(project.References, "REFERENCES");
            log.WriteList(project.Dependencies, "DEPENDENCIES");
            log.WriteList(project.CscOptions, "CSCOPTIONS");
            log.WriteLine("-------------------------------------------------");
        }
Beispiel #20
0
 private static void OutputRuntimeDependenciesAction(ProjectProperties properties, Log log)
 {
     foreach (var dependencyFolder in properties.Dependencies)
     {
         Helpers.CopyFile(dependencyFolder, properties.OutputDirectory, log);
     }
 }
        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;
        }
        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("win")) ? ".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);
        }