public static string GenerateUnifiedLibraryProject(UnifiedTestConfig config)
        {
            string sourceDir      = FindSourceDirectory();
            string sourceFileName = config.FSharp ? "Component1.fs" : "MyClass.cs";
            string projectSuffix  = config.FSharp ? ".fsproj" : ".csproj";

            File.Copy(Path.Combine(sourceDir, sourceFileName), Path.Combine(config.TmpDir, sourceFileName), true);

            return(CopyFileWithSubstitutions(Path.Combine(sourceDir, config.ProjectName + projectSuffix), Path.Combine(config.TmpDir, config.ProjectName + projectSuffix), text => {
                return ProjectTextReplacement(config, text);
            }));
        }
        public static string GenerateBindingLibraryProject(UnifiedTestConfig config)
        {
            var info = TemplateInfo.FromCustomProject(ProjectType.Binding, ProjectLanguage.CSharp, config.ProjectName);

            var engine            = new MacBindingTemplateEngine(info);
            var fileSubstitutions = new FileSubstitutions {
                ApiDefinition   = config.APIDefinitionConfig,
                StructsAndEnums = config.StructsAndEnumsConfig
            };

            return(engine.Generate(config.TmpDir, CreateDefaultSubstitutions(config), fileSubstitutions));
        }
 static ProjectSubstitutions CreateDefaultSubstitutions(UnifiedTestConfig config)
 {
     return(new ProjectSubstitutions {
         CSProjConfig = config.CSProjConfig,
         References = config.References,
         ReferencesBeforePlatform = config.ReferencesBeforePlatform,
         AssemblyNameOverride = config.AssemblyName ?? Path.GetFileNameWithoutExtension(config.ProjectName),
         ItemGroup = config.ItemGroup,
         TargetFrameworkVersion = config.TargetFrameworkVersion,
         CustomProjectReplacement = config.CustomProjectReplacement
     });
 }
        public static string GenerateEXEProject(UnifiedTestConfig config)
        {
            WriteMainFile(config.TestDecl, config.TestCode, true, config.FSharp, Path.Combine(config.TmpDir, config.FSharp ? "Main.fs" : "Main.cs"));

            string sourceDir = FindSourceDirectory();

            File.Copy(Path.Combine(sourceDir, "Info-Unified.plist"), Path.Combine(config.TmpDir, "Info.plist"), true);

            return(CopyFileWithSubstitutions(Path.Combine(sourceDir, config.ProjectName), Path.Combine(config.TmpDir, config.ProjectName), text =>
            {
                return ProjectTextReplacement(config, text);
            }));
        }
Example #5
0
        public static string GenerateSystemMonoEXEProject(UnifiedTestConfig config)
        {
            WriteMainFile(config.TestDecl, config.TestCode, true, false, Path.Combine(config.TmpDir, "Main.cs"));

            string sourceDir = FindSourceDirectory();

            File.Copy(Path.Combine(sourceDir, "Info-Unified.plist"), Path.Combine(config.TmpDir, "Info.plist"), true);

            return(CopyFileWithSubstitutions(Path.Combine(sourceDir, config.ProjectName), Path.Combine(config.TmpDir, config.ProjectName), text =>
            {
                return ProjectTextReplacement(config, text.Replace("%TARGETFRAMEWORKVERSION%", GetTargetFrameworkValue(config)));
            }));
        }
Example #6
0
 static string ProjectTextReplacement(UnifiedTestConfig config, string text)
 {
     text = text.Replace("%CODE%", config.CSProjConfig)
            .Replace("%REFERENCES%", config.References)
            .Replace("%REFERENCES_BEFORE_PLATFORM%", config.ReferencesBeforePlatform)
            .Replace("%NAME%", config.AssemblyName ?? Path.GetFileNameWithoutExtension(config.ProjectName))
            .Replace("%ITEMGROUP%", config.ItemGroup)
            .Replace("%TARGET_FRAMEWORK_VERSION%", config.TargetFrameworkVersion);
     if (config.CustomProjectReplacement != null)
     {
         text = text.Replace(config.CustomProjectReplacement.Item1, config.CustomProjectReplacement.Item2);
     }
     return(text);
 }
Example #7
0
        public static OutputText TestUnifiedExecutable(UnifiedTestConfig config, bool shouldFail = false, string[] environment = null)
        {
            AddGUIDTestCode(config);

            string buildOutput = GenerateAndBuildUnifiedExecutable(config, shouldFail, environment);

            if (shouldFail)
            {
                return(new OutputText(buildOutput, ""));
            }

            string runOutput = RunGeneratedUnifiedExecutable(config);

            return(new OutputText(buildOutput, runOutput));
        }
Example #8
0
        public static string GetUnifiedExecutableProjectName(UnifiedTestConfig config)
        {
            string projectName;

            if (config.FSharp)
            {
                projectName = config.XM45 ? "FSharpXM45Example" : "FSharpUnifiedExample";
            }
            else
            {
                projectName = config.XM45 ? "XM45Example" : "UnifiedExample";
            }
            string projectExtension = config.FSharp ? ".fsproj" : ".csproj";

            return(projectName + projectExtension);
        }
Example #9
0
        public static string GenerateNetStandardProject(UnifiedTestConfig config)
        {
            const string SourceFile        = "Class1.cs";
            const string ProjectFile       = "NetStandardLib.csproj";
            const string NetStandardSubDir = "NetStandard";

            string sourceDir = FindSourceDirectory();

            Directory.CreateDirectory(Path.Combine(config.TmpDir, NetStandardSubDir));
            File.Copy(Path.Combine(sourceDir, NetStandardSubDir, SourceFile), Path.Combine(config.TmpDir, NetStandardSubDir, SourceFile), true);

            string projectPath = Path.Combine(config.TmpDir, NetStandardSubDir, ProjectFile);

            File.Copy(Path.Combine(sourceDir, NetStandardSubDir, ProjectFile), projectPath, true);

            return(projectPath);
        }
        public static string BuildUnifiedExecutable(UnifiedTestConfig config, bool shouldFail = false)
        {
            string projectName;

            if (config.FSharp)
            {
                projectName = config.XM45 ? "FSharpXM45Example" : "FSharpUnifiedExample";
            }
            else
            {
                projectName = config.XM45 ? "XM45Example" : "UnifiedExample";
            }
            string projectExtension = config.FSharp ? ".fsproj" : ".csproj";

            config.ProjectName = projectName + projectExtension;
            string csprojTarget = GenerateEXEProject(config);

            return(BuildProject(csprojTarget, isUnified: true, shouldFail: shouldFail));
        }
        public static OutputText TestUnifiedExecutable(UnifiedTestConfig config, bool shouldFail = false, string configuration = null)
        {
            // If we've already generated guid bits for this config, don't tack on a second copy
            if (config.guid == Guid.Empty)
            {
                config.guid      = Guid.NewGuid();
                config.TestCode += GenerateOutputCommand(config.TmpDir, config.guid);
            }

            string buildOutput = GenerateAndBuildUnifiedExecutable(config, shouldFail, configuration);

            if (shouldFail)
            {
                return(new OutputText(buildOutput, ""));
            }

            string runOutput = RunGeneratedUnifiedExecutable(config);

            return(new OutputText(buildOutput, runOutput));
        }
Example #12
0
        public static OutputText TestSystemMonoExecutable(UnifiedTestConfig config, bool shouldFail = false)
        {
            Guid guid        = Guid.NewGuid();
            var  projectName = "SystemMonoExample";

            config.TestCode   += GenerateOuputCommand(config.TmpDir, guid);
            config.ProjectName = $"{projectName}.csproj";
            string csprojTarget = GenerateSystemMonoEXEProject(config);

            string buildOutput = BuildProject(csprojTarget, isUnified: true, diagnosticMSBuild: config.DiagnosticMSBuild, shouldFail: shouldFail);

            if (shouldFail)
            {
                return(new OutputText(buildOutput, ""));
            }

            string exePath   = Path.Combine(config.TmpDir, "bin/Debug/" + projectName + ".app/Contents/MacOS/" + projectName);
            string runOutput = RunEXEAndVerifyGUID(config.TmpDir, guid, exePath);

            return(new OutputText(buildOutput, runOutput));
        }
Example #13
0
        public static OutputText TestSystemMonoExecutable(UnifiedTestConfig config, bool shouldFail = false)
        {
            config.guid = Guid.NewGuid();
            var projectName = "SystemMonoExample";

            config.TestCode   += GenerateOutputCommand(config.TmpDir, config.guid);
            config.ProjectName = $"{projectName}.csproj";
            string csprojTarget = GenerateSystemMonoEXEProject(config);

            string buildOutput = BuildProject(csprojTarget, isUnified: true, shouldFail: shouldFail, release: config.Release);

            if (shouldFail)
            {
                return(new OutputText(buildOutput, ""));
            }

            string exePath   = Path.Combine(config.TmpDir, "bin", config.Release ? "Release" : "Debug", projectName + ".app", "Contents", "MacOS", projectName);
            string runOutput = RunEXEAndVerifyGUID(config.TmpDir, config.guid, exePath);

            return(new OutputText(buildOutput, runOutput));
        }
Example #14
0
        public static string GenerateEXEProject(UnifiedTestConfig config)
        {
            WriteMainFile(config.TestDecl, config.TestCode, true, config.FSharp, Path.Combine(config.TmpDir, config.FSharp ? "Main.fs" : "Main.cs"));

            string sourceDir = FindSourceDirectory();

            if (config.AssetIcons)
            {
                RunAndAssert("/bin/cp", $"-R {Path.Combine (sourceDir, "Icons/Assets.xcassets")} {config.TmpDir}", "Copy Asset Icons");
                config.ItemGroup += @"<ItemGroup>
    <ImageAsset Include=""Assets.xcassets\AppIcon.appiconset\Contents.json"" />
    <ImageAsset Include=""Assets.xcassets\AppIcon.appiconset\AppIcon-128.png"" />
    <ImageAsset Include=""Assets.xcassets\AppIcon.appiconset\AppIcon-128%402x.png"" />
    <ImageAsset Include=""Assets.xcassets\AppIcon.appiconset\AppIcon-16.png"" />
    <ImageAsset Include=""Assets.xcassets\AppIcon.appiconset\AppIcon-16%402x.png"" />
    <ImageAsset Include=""Assets.xcassets\AppIcon.appiconset\AppIcon-256%402x.png"" />
    <ImageAsset Include=""Assets.xcassets\AppIcon.appiconset\AppIcon-32.png"" />
    <ImageAsset Include=""Assets.xcassets\AppIcon.appiconset\AppIcon-32%402x.png"" />
    <ImageAsset Include=""Assets.xcassets\Contents.json"" />
  </ItemGroup>";
                // HACK - Should process using CopyFileWithSubstitutions
                config.PlistReplaceStrings.Add("</dict>", @"<key>XSAppIconAssets</key><string>Assets.xcassets/AppIcon.appiconset</string></dict>");
            }

            CopyFileWithSubstitutions(Path.Combine(sourceDir, "Info-Unified.plist"), Path.Combine(config.TmpDir, "Info.plist"), text => {
                foreach (var key in config.PlistReplaceStrings.Keys)
                {
                    text = text.Replace(key, config.PlistReplaceStrings [key]);
                }

                return(text);
            });

            return(CopyFileWithSubstitutions(Path.Combine(sourceDir, config.ProjectName), Path.Combine(config.TmpDir, config.ProjectName), text =>
            {
                return ProjectTextReplacement(config, text);
            }));
        }
Example #15
0
 public static string RunGeneratedUnifiedExecutable(UnifiedTestConfig config)
 {
     return(RunEXEAndVerifyGUID(config.TmpDir, config.guid, config.ExecutablePath));
 }
Example #16
0
        static string GetTargetFrameworkValue(UnifiedTestConfig config)
        {
            string version = config.SystemMonoVersion == "" ? "4.5" : config.SystemMonoVersion;

            return(string.Format("<TargetFrameworkVersion>v{0}</TargetFrameworkVersion>", version));
        }
        public static string GenerateNetStandardProject(UnifiedTestConfig config)
        {
            NetStandardLibraryTemplateEngine engine = new NetStandardLibraryTemplateEngine();

            return(engine.Generate(config.TmpDir));
        }
Example #18
0
        public static string GenerateAndBuildUnifiedExecutable(UnifiedTestConfig config, bool shouldFail = false, string[] environment = null)
        {
            string csprojTarget = GenerateUnifiedExecutableProject(config);

            return(BuildProject(csprojTarget, isUnified: true, shouldFail: shouldFail, release: config.Release, environment: environment));
        }
Example #19
0
 public static string GenerateUnifiedExecutableProject(UnifiedTestConfig config)
 {
     config.ProjectName = GetUnifiedExecutableProjectName(config);
     return(GenerateEXEProject(config));
 }
 static string ProjectTextReplacement(UnifiedTestConfig config, string text)
 {
     return(text.Replace("%CODE%", config.CSProjConfig).Replace("%REFERENCES%", config.References).Replace("%NAME%", config.AssemblyName ?? Path.GetFileNameWithoutExtension(config.ProjectName)).Replace("%ITEMGROUP%", config.ItemGroup));
 }
        public static string GenerateAndBuildUnifiedExecutable(UnifiedTestConfig config, bool shouldFail = false, string configuration = null)
        {
            string csprojTarget = GenerateUnifiedExecutableProject(config);

            return(BuildProject(csprojTarget, isUnified: true, diagnosticMSBuild: config.DiagnosticMSBuild, shouldFail: shouldFail, configuration: configuration));
        }
        public static BuildResult GenerateAndBuildUnifiedExecutable(UnifiedTestConfig config, bool shouldFail = false, Dictionary <string, string> environment = null)
        {
            string csprojTarget = GenerateUnifiedExecutableProject(config);

            return(BuildProject(csprojTarget, shouldFail: shouldFail, release: config.Release, environment: environment));
        }