Example #1
0
        public override bool AddToProject(SolutionItem policyParent, Project project, string language, string directory, string name)
        {
            var path = FilePath.Build(directory, project.Name + "-res.zip");
            var file = new ProjectFile(path, "EmbeddedResource");

            file.ResourceId = "XobotOS.Resources";
            file.Visible    = false;
            project.AddFile(file);
            return(true);
        }
Example #2
0
        protected override ClientAppPaths CreateClientAppPaths()
        {
            var basePath = FilePath.Build(
                Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
                "com.xamarin.workbooks.console");

            return(new ClientAppPaths(
                       basePath.Combine("logs"),
                       basePath.Combine("preferences"),
                       basePath.Combine("cache")));
        }
Example #3
0
        /// <summary>
        /// This is a workaround to allow F# .NET Core 2.0 projects to be evaluated properly and compile
        /// without any errors. The better solution would be to ship the new Microsoft.FSharp.NetSdk.props
        /// and .targets files with Mono so this workaround can be removed. Setting the FSharpPropsShim
        /// and FSharpTargetsShim as environment variables allows the correct MSBuild imports to be used
        /// when building and evaluating. Just setting a global MSBuild property would fix the Build target
        /// not being found but the MSBuild project evaluation would not add the FSharp.Core PackageReference
        /// to the project.assets.json file, also all .fs files were treated as None items instead of
        /// Compile items.
        /// </summary>
        static void SetFSharpShims()
        {
            var latestVersion = Versions.FirstOrDefault();

            if (latestVersion != null && latestVersion.Major == 2)
            {
                FilePath directory = FilePath.Build(MSBuildSDKsPath, "..", "FSharp");

                Environment.SetEnvironmentVariable("FSharpPropsShim", directory.Combine("Microsoft.FSharp.NetSdk.props").FullPath);
                Environment.SetEnvironmentVariable("FSharpTargetsShim", directory.Combine("Microsoft.FSharp.NetSdk.targets").FullPath);
            }
        }
 private IronPythonObject()
 {
     DefaultSearchPaths = new System.Collections.Generic.List <string>()
     {
         ".",
         Settings.RootPath + FilePath.Build(FilePath.Build("ipy", "Lib")),
         Settings.RootPath + FilePath.Build(FilePath.Build("ipy", "DLLs")),
         Settings.RootPath + FilePath.Build(FilePath.Build("ipy", "Lib", "site-packages"))
     };
     Engine = IronPython.Hosting.Python.CreateEngine() /*.CreateScope()*/;
     Scope  = Engine.CreateScope();
 }
Example #5
0
        public void SetPrivateDirectories(string[] directories)
        {
            if (directories == null || directories.Length == 0)
            {
                return;
            }

            PrivateDirectories = new string[directories.Length];
            for (int i = directories.Length - 1; i > -1; i--)
            {
                PrivateDirectories[i] = Path + FilePath.Build(directories[i]);
            }
        }
        public void OpenedArchiveIsRearchivedOnSave()
        {
            var workbookPath = FilePath.Build(PathToSaveAndLoad, "SinglePageWithDepsAsArchive.workbook");

            workbookPath = GetTemporaryCopyOfWorkbook(workbookPath);

            var workbook      = ReadWorkbookDocument(workbookPath);
            var workbookFiles = GetWorkbookFileState(workbook.WorkingPath);

            workbook.Save(workbookPath);

            AssertWorkbookIsReArchived(workbookPath, workbookFiles);
        }
        public void OpenedArchiveDepsAreSaved()
        {
            var workbookPath = FilePath.Build(PathToSaveAndLoad, "SinglePageWithDepsAsArchive.workbook");

            workbookPath = GetTemporaryCopyOfWorkbook(workbookPath);
            var savePath = workbookPath.ParentDirectory.Combine("NewWorkbookPath.workbook");

            var workbook      = ReadWorkbookDocument(workbookPath);
            var workbookFiles = GetWorkbookFileState(workbook.WorkingPath);

            workbook.Save(savePath);

            AssertWorkbookIsReArchived(savePath, workbookFiles);
        }
        /// <summary>
        /// Convert relative reference paths to absolute paths. Requires the package
        /// to already be installed/restored.
        /// </summary>
        ImmutableList <FilePath> RelativeToAbsolute(
            IReadOnlyList <string> relativeReferences,
            PackageIdentity packageIdentity)
        {
            if (relativeReferences == null)
            {
                return(ImmutableList <FilePath> .Empty);
            }

            var packageInstallPath = GetInstalledPath(packageIdentity);

            return(relativeReferences
                   .Select(r => FilePath.Build(packageInstallPath, r))
                   .ToImmutableList());
        }
        public string GetInstalledPath(PackageIdentity packageIdentity)
        {
            if (packageIdentity == null)
            {
                throw new ArgumentNullException(nameof(packageIdentity));
            }
            if (!packageIdentity.HasVersion)
            {
                throw new ArgumentException("PackageIdentity.Version must be set");
            }

            return(FilePath.Build(
                       packagesDirectory,
                       packageIdentity.Id.ToLower(),
                       packageIdentity.Version.ToNormalizedString()));
        }
        FilePath GetDefaultTemplateJsonFilePath()
        {
            string directory = Path.GetDirectoryName(GetType().Assembly.Location);

            return(FilePath.Build(directory, "ConfigurationFiles", "template.json"));
        }
Example #11
0
 public void SetStartupFile(string file) => StartupFile = Path + FilePath.Build(file);
Example #12
0
 public void SetConnectionHandler(string connHandler) => ConnectionHandler = Path + FilePath.Build(connHandler);
Example #13
0
 public void SetUploadDirectory(string uploadDirectory) => UploadDirectory = Path + FilePath.Build(uploadDirectory);
Example #14
0
        public static void SetSource(dynamic p)
        {
            if (p == null)
            {
                throw new ArgumentNullException(nameof(p));
            }

            SourcePath = PathResolver.Build((string)p.Source);
            if (!SourcePath[SourcePath.Length - 1].Equals(System.IO.Path.DirectorySeparatorChar))
            {
                SourcePath += System.IO.Path.DirectorySeparatorChar;
            }
            SettingsFilePath = SourcePath + FilePath.Build("root", "settings.json");
            BasePath         = SourcePath;// + $"base{System.IO.Path.DirectorySeparatorChar}";
            RootPath         = BasePath + $"root{System.IO.Path.DirectorySeparatorChar}";
            ResourcePath     = BasePath + $"res{System.IO.Path.DirectorySeparatorChar}";
            FeatureSetPath   = p.FeaturesSet == null ? null : (string)p.FeaturesSet;
            Features         = new System.Collections.Generic.Dictionary <string, Feature>();
            if (FeatureSetPath != null)
            {
                ProcessorArchitecture arch = Assembly.GetExecutingAssembly().GetName().ProcessorArchitecture;
                if (arch == ProcessorArchitecture.MSIL)
                {
                    System.Runtime.InteropServices.Architecture osarch = System.Runtime.InteropServices.RuntimeInformation.OSArchitecture;
                    arch = osarch == System.Runtime.InteropServices.Architecture.Arm ? ProcessorArchitecture.Arm :
                           osarch == System.Runtime.InteropServices.Architecture.X64 ? ProcessorArchitecture.Amd64 :
                           osarch == System.Runtime.InteropServices.Architecture.X86 ? ProcessorArchitecture.X86 : ProcessorArchitecture.X86;
                }
                dynamic features = Newtonsoft.Json.JsonConvert.DeserializeObject(System.IO.File.ReadAllText(FeatureSetPath + "config.json"));
                foreach (dynamic feature in features)
                {
                    ProcessorArchitecture featureArch = GetArchitecture(((string)feature.Architecture).Trim(), arch);
                    if (!arch.Equals(featureArch))
                    {
                        if (arch == ProcessorArchitecture.Amd64 && featureArch == ProcessorArchitecture.X86)
                        {
                            ;
                        }
                        else if ((arch == ProcessorArchitecture.Amd64 || arch == ProcessorArchitecture.X86) && Environment.Is64BitProcess)
                        {
                            ;
                        }
                        else
                        {
                            ErrorLogger.Warn("[Settings] : Feature '" + (string)feature.Name + "' Unknown architecture '" + arch + "', feature dropped >> " + featureArch.ToString());
                            continue;
                        }
                    }


                    Feature f = new()
                    {
                        Name = (string)feature.Name,
                        Path = FeatureSetPath + (string)feature.Name + System.IO.Path.DirectorySeparatorChar + (
                            featureArch == ProcessorArchitecture.Amd64 ? "x64" + System.IO.Path.DirectorySeparatorChar :
                            featureArch == ProcessorArchitecture.X86 ? "x86" + System.IO.Path.DirectorySeparatorChar :
                            featureArch == ProcessorArchitecture.Arm ? "arm" + System.IO.Path.DirectorySeparatorChar : null
                            ),
                        TargetName           = (string)feature.Target,
                        RequireServerIOFocus = (bool)feature.RequireServerIOFocus,
                        WaitForExit          = (bool)feature.WaitForExit
                    };

                    f.TargetExcutable = f.Path + f.TargetName;

                    if (!System.IO.File.Exists(f.TargetExcutable) || f.Path == null)
                    {
                        ErrorLogger.Warn("[Settings] : Feature '" + (string)feature.Name + "' Target file not found, won't be available");
                        continue;
                    }
                    if (!(bool)feature.Enabled)
                    {
                        continue;
                    }
                    if (Features.ContainsKey(f.Name))
                    {
                        ErrorLogger.Warn("[Settings] : Feature '" + (string)feature.Name + "' already defined. duplicates ignored");
                        continue;
                    }

                    Features.Add(f.Name, f);
                }

                if (!Features.ContainsKey("cpython"))
                {
                    throw new Exception("Cannot initialize feature-set without cpython");
                }
            }
        }
        public static int?GetRhinoVersion(this IBuildTarget item)
        {
            var project = item as DotNetProject;

            if (project == null)
            {
                return(null);
            }

            var isv6 = project.ExtendedProperties[s_RhinoVersionKey] as int?;

            if (isv6 != null)
            {
                return(isv6.Value);
            }

            if (int.TryParse(project.ProjectProperties.GetValue <string>("RhinoVersion"), out var ver))
            {
                project.ExtendedProperties[s_RhinoVersionKey] = ver;
                return(ver);
            }

            // check grasshopper first as those projects reference both RhinoCommon and Grasshopper
            var reference = project.References.FirstOrDefault(r => r.Reference == GrasshopperReferenceName);

            if (reference == null)
            {
                reference = project.References.FirstOrDefault(r => r.Reference == RhinoCommonReferenceName);
            }

            int?result = null;

            if (reference?.ReferenceType == ReferenceType.Project)
            {
                // the reference is a project type, assume v6
                // and in v5 we include our own props file
                result = 6;
            }
            else if (reference != null)
            {
                try
                {
                    var absPath = project.GetAbsoluteChildPath(FilePath.Build(reference.HintPath));
                    if (File.Exists(absPath.FullPath))
                    {
                        var raw = File.ReadAllBytes(absPath.FullPath);
                        var asm = Assembly.ReflectionOnlyLoad(raw);
                        Console.WriteLine($"Found Rhino assembly version {asm.GetName().Version}");
                        result = asm.GetName().Version.Major;
                    }
                }
                catch (Exception ex)
                {
                    // ignore errors here!
                    Console.WriteLine($"Exception was thrown trying to read Rhino assembly version {ex}");
                }
            }

            if (result == null)
            {
                foreach (var projectItem in project.Items.OfType <ProjectItem>().Where(r => r.ItemName == "PackageReference"))
                {
                    if (projectItem.Include == GrasshopperReferenceName ||
                        projectItem.Include == RhinoCommonReferenceName)
                    {
                        var version = projectItem.Metadata.GetValue("Version");
                        var idx     = version?.IndexOf('.') ?? -1;
                        if (idx > 0)
                        {
                            if (int.TryParse(version.Substring(0, idx), out var r))
                            {
                                result = r;
                            }
                        }
                        break;
                    }
                }
            }
            project.ExtendedProperties[s_RhinoVersionKey] = result;
            return(result);
        }
Example #16
0
        FilePath GetSourceGitIgnoreFilePath()
        {
            string directory = Path.GetDirectoryName(typeof(ProjectTemplateHandler).Assembly.Location);

            return(FilePath.Build(directory, "GitIgnore.txt"));
        }
        static string GetExeLocation(string toolsVersion)
        {
            FilePath sourceExe = typeof(ProjectBuilder).Assembly.Location;

            if (toolsVersion == REFERENCED_MSBUILD_TOOLS)
            {
                return(sourceExe);
            }

            var    newVersions = new Dictionary <string, string[]> ();
            string version;

            Mono.Cecil.TargetRuntime runtime;

            switch (toolsVersion)
            {
            case "2.0":
                version = "2.0.0.0";
                newVersions.Add("Microsoft.Build.Engine", new string[] { "Microsoft.Build.Engine", version });
                newVersions.Add("Microsoft.Build.Framework", new string[] { "Microsoft.Build.Framework", version });
                newVersions.Add(REFERENCED_MSBUILD_UTILS, new string[] { "Microsoft.Build.Utilities", version });
                runtime = Mono.Cecil.TargetRuntime.Net_2_0;
                break;

            case "3.5":
                version = "3.5.0.0";
                newVersions.Add("Microsoft.Build.Engine", new string[] { "Microsoft.Build.Engine", version });
                newVersions.Add("Microsoft.Build.Framework", new string[] { "Microsoft.Build.Framework", version });
                newVersions.Add(REFERENCED_MSBUILD_UTILS, new string[] { "Microsoft.Build.Utilities.v3.5", version });
                runtime = Mono.Cecil.TargetRuntime.Net_2_0;
                break;

            case "4.0":
                version = "4.0.0.0";
                newVersions.Add("Microsoft.Build.Engine", new string[] { "Microsoft.Build.Engine", version });
                newVersions.Add("Microsoft.Build.Framework", new string[] { "Microsoft.Build.Framework", version });
                newVersions.Add(REFERENCED_MSBUILD_UTILS, new string[] { "Microsoft.Build.Utilities.v4.0", version });
                runtime = Mono.Cecil.TargetRuntime.Net_4_0;
                break;

            default:
                throw new InvalidOperationException("Unknown MSBuild ToolsVersion '" + toolsVersion + "'");
            }

            FilePath p = FilePath.Build(PropertyService.Locations.Cache, "xbuild", toolsVersion, "MonoDevelop.Projects.Formats.MSBuild.exe");

            if (!File.Exists(p) || File.GetLastWriteTime(p) < File.GetLastWriteTime(sourceExe))
            {
                if (!Directory.Exists(p.ParentDirectory))
                {
                    Directory.CreateDirectory(p.ParentDirectory);
                }

                // Update the references to msbuild
                Cecil.AssemblyDefinition asm = Cecil.AssemblyDefinition.ReadAssembly(sourceExe);
                foreach (Cecil.AssemblyNameReference ar in asm.MainModule.AssemblyReferences)
                {
                    string[] replacement;
                    if (newVersions.TryGetValue(ar.Name, out replacement))
                    {
                        ar.Name    = replacement[0];
                        ar.Version = new Version(replacement[1]);
                    }
                }
                asm.MainModule.Runtime = runtime;

                //run in 32-bit mode because usually msbuild targets are installed for 32-bit only
                asm.MainModule.Attributes |= Mono.Cecil.ModuleAttributes.Required32Bit;

                // Workaround to a bug in mcs. The ILOnly flag is not emitted when using /platform:x86
                asm.MainModule.Attributes |= Mono.Cecil.ModuleAttributes.ILOnly;

                asm.Write(p);
            }

            FilePath configFile = p + ".config";
            FilePath configSrc  = typeof(ProjectBuilder).Assembly.Location + ".config";

            if (!File.Exists(configFile) || File.GetLastWriteTime(configFile) < File.GetLastWriteTime(configSrc))
            {
                var config = File.ReadAllText(configSrc);
                config = config.Replace(REFERENCED_MSBUILD_TOOLS + ".0.0", version);
                File.WriteAllText(p + ".config", config);
            }
            return(p);
        }
Example #18
0
 public void SetHome(string h) => HomeFile         = Path + FilePath.Build(h);