internal static bool EnsureProjectLockFile(string projectLockFile)
 {
     return(MicrosoftCSharpCompiler.EnsureProjectLockFile(new NuGetPackageResolver()
     {
         ProjectLockFile = projectLockFile
     }));
 }
        public static string[] Compile(string[] sources, string[] references, string[] defines, string outputFile, bool allowUnsafeCode)
        {
            var assembly = new ScriptAssembly
            {
                BuildTarget              = BuildTarget.StandaloneWindows,
                Files                    = sources,
                References               = references,
                Defines                  = defines,
                OutputDirectory          = AssetPath.GetDirectoryName(outputFile),
                Filename                 = AssetPath.GetFileName(outputFile),
                CompilerOptions          = new Compilation.ScriptCompilerOptions(),
                ScriptAssemblyReferences = new ScriptAssembly[0]
            };

            assembly.CompilerOptions.AllowUnsafeCode       = allowUnsafeCode;
            assembly.CompilerOptions.ApiCompatibilityLevel = ApiCompatibilityLevel.NET_Standard_2_0;

            using (var c = new MicrosoftCSharpCompiler(assembly, assembly.OutputDirectory))
            {
                c.BeginCompiling();
                while (!c.Poll())
                {
                    System.Threading.Thread.Sleep(50);
                }
                return(c.GetCompilerMessages().Select(cm => cm.message).ToArray());
            }
        }
예제 #3
0
        internal static string GetPlatformAssemblyPath(WSASDK wsaSDK)
        {
            string windowsKitDirectory = MicrosoftCSharpCompiler.GetWindowsKitDirectory(wsaSDK);
            string result;

            if (wsaSDK == WSASDK.UWP)
            {
                string text = Paths.Combine(new string[]
                {
                    windowsKitDirectory,
                    "UnionMetadata",
                    UWPReferences.SdkVersionToString(UWPReferences.GetDesiredSDKVersion()),
                    "Facade",
                    "Windows.winmd"
                });
                if (!File.Exists(text))
                {
                    text = Path.Combine(windowsKitDirectory, "UnionMetadata\\Facade\\Windows.winmd");
                }
                result = text;
            }
            else
            {
                result = Path.Combine(windowsKitDirectory, "References\\CommonConfiguration\\Neutral\\Windows.winmd");
            }
            return(result);
        }
예제 #4
0
        internal static string GetNETCoreFrameworkReferencesDirectory(WSASDK wsaSDK)
        {
            string result;

            if (MicrosoftCSharpCompiler.GetCurrentScriptingBackend() != ScriptingImplementation.IL2CPP)
            {
                switch (wsaSDK)
                {
                case WSASDK.SDK80:
                    result = MicrosoftCSharpCompiler.ProgramFilesDirectory + "\\Reference Assemblies\\Microsoft\\Framework\\.NETCore\\v4.5";
                    return(result);

                case WSASDK.SDK81:
                    result = MicrosoftCSharpCompiler.ProgramFilesDirectory + "\\Reference Assemblies\\Microsoft\\Framework\\.NETCore\\v4.5.1";
                    return(result);

                case WSASDK.PhoneSDK81:
                    result = MicrosoftCSharpCompiler.ProgramFilesDirectory + "\\Reference Assemblies\\Microsoft\\Framework\\WindowsPhoneApp\\v8.1";
                    return(result);

                case WSASDK.UWP:
                    result = null;
                    return(result);
                }
                throw new Exception("Unknown Windows SDK: " + wsaSDK.ToString());
            }
            result = BuildPipeline.GetMonoLibDirectory(BuildTarget.WSAPlayer);
            return(result);
        }
        private string[] GetNETWSAAssemblies(WSASDK wsaSDK)
        {
            if (wsaSDK != WSASDK.UWP || MicrosoftCSharpCompiler.GetCurrentScriptingBackend() == ScriptingImplementation.IL2CPP)
            {
                return(Directory.GetFiles(MicrosoftCSharpCompiler.GetNETCoreFrameworkReferencesDirectory(wsaSDK), "*.dll"));
            }
            NuGetPackageResolver nuGetPackageResolver = new NuGetPackageResolver
            {
                ProjectLockFile = "UWP\\project.lock.json"
            };

            for (int num = (!MicrosoftCSharpCompiler.EnsureProjectLockFile(nuGetPackageResolver)) ? 1 : 2; num != 0; num--)
            {
                try
                {
                    nuGetPackageResolver.Resolve();
                }
                catch (Exception)
                {
                    if (num <= 1)
                    {
                        throw;
                    }
                    Console.WriteLine("Failed to resolve NuGet packages. Deleting \"{0}\" and retrying.", Path.GetFullPath(nuGetPackageResolver.ProjectLockFile));
                    File.Delete(nuGetPackageResolver.ProjectLockFile);
                    MicrosoftCSharpCompiler.EnsureProjectLockFile(nuGetPackageResolver);
                }
            }
            return(nuGetPackageResolver.ResolvedReferences);
        }
        protected static string GetPlatformAssemblyPath(WSASDK wsaSDK)
        {
            string windowsKitDirectory = MicrosoftCSharpCompiler.GetWindowsKitDirectory(wsaSDK);

            if (wsaSDK == WSASDK.UWP)
            {
                return(Path.Combine(windowsKitDirectory, "UnionMetadata\\Facade\\Windows.winmd"));
            }
            return(Path.Combine(windowsKitDirectory, "References\\CommonConfiguration\\Neutral\\Windows.winmd"));
        }
예제 #7
0
        public override ScriptCompilerBase CreateCompiler(MonoIsland island, bool buildingForEditor, BuildTarget targetPlatform, bool runUpdater)
        {
            CSharpCompiler     cSharpCompiler = CSharpLanguage.GetCSharpCompiler(targetPlatform, buildingForEditor, island._output);
            ScriptCompilerBase result;

            if (cSharpCompiler != CSharpCompiler.Microsoft)
            {
                if (cSharpCompiler != CSharpCompiler.Mono)
                {
                }
                result = new MonoCSharpCompiler(island, runUpdater);
            }
            else
            {
                result = new MicrosoftCSharpCompiler(island, runUpdater);
            }
            return(result);
        }
        private string[] GetClassLibraries()
        {
            BuildTargetGroup buildTargetGroup = BuildPipeline.GetBuildTargetGroup(this.BuildTarget);

            string[] result;
            if (PlayerSettings.GetScriptingBackend(buildTargetGroup) != ScriptingImplementation.WinRTDotNET)
            {
                string        monoAssemblyDirectory = base.GetMonoProfileLibDirectory();
                List <string> list = new List <string>();
                list.AddRange(from dll in MicrosoftCSharpCompiler.GetReferencesFromMonoDistribution()
                              select Path.Combine(monoAssemblyDirectory, dll));
                if (PlayerSettings.GetApiCompatibilityLevel(buildTargetGroup) == ApiCompatibilityLevel.NET_4_6)
                {
                    string path = Path.Combine(monoAssemblyDirectory, "Facades");
                    list.Add(Path.Combine(path, "System.ObjectModel.dll"));
                    list.Add(Path.Combine(path, "System.Runtime.dll"));
                    list.Add(Path.Combine(path, "System.Runtime.InteropServices.WindowsRuntime.dll"));
                    list.Add(Path.Combine(monoAssemblyDirectory, "System.Numerics.dll"));
                    list.Add(Path.Combine(monoAssemblyDirectory, "System.Numerics.Vectors.dll"));
                }
                result = list.ToArray();
            }
            else
            {
                if (this.BuildTarget != BuildTarget.WSAPlayer)
                {
                    throw new InvalidOperationException(string.Format("MicrosoftCSharpCompiler cannot build for .NET Scripting backend for BuildTarget.{0}.", this.BuildTarget));
                }
                WSASDK wSASDK = WSASDK.UWP;
                if (wSASDK != WSASDK.UWP)
                {
                    result = Directory.GetFiles(MicrosoftCSharpCompiler.GetNETCoreFrameworkReferencesDirectory(wSASDK), "*.dll");
                }
                else
                {
                    NuGetPackageResolver nuGetPackageResolver = new NuGetPackageResolver
                    {
                        ProjectLockFile = "UWP\\project.lock.json"
                    };
                    result = nuGetPackageResolver.Resolve();
                }
            }
            return(result);
        }
        private string[] GetNETWSAAssemblies(WSASDK wsaSDK)
        {
            if (MicrosoftCSharpCompiler.GetCurrentScriptingBackend() == ScriptingImplementation.IL2CPP)
            {
                string monoAssemblyDirectory = BuildPipeline.GetMonoLibDirectory(BuildTarget.WSAPlayer);
                return((from dll in MicrosoftCSharpCompiler.GetReferencesFromMonoDistribution()
                        select Path.Combine(monoAssemblyDirectory, dll)).ToArray <string>());
            }
            if (wsaSDK != WSASDK.UWP)
            {
                return(Directory.GetFiles(MicrosoftCSharpCompiler.GetNETCoreFrameworkReferencesDirectory(wsaSDK), "*.dll"));
            }
            NuGetPackageResolver nuGetPackageResolver = new NuGetPackageResolver
            {
                ProjectLockFile = "UWP\\project.lock.json"
            };

            return(nuGetPackageResolver.Resolve());
        }
        private string[] GetNETWSAAssemblies(WSASDK wsaSDK)
        {
            if (MicrosoftCSharpCompiler.GetCurrentScriptingBackend() == ScriptingImplementation.IL2CPP)
            {
                // ISSUE: object of a compiler-generated type is created
                // ISSUE: reference to a compiler-generated method
                return(((IEnumerable <string>)MicrosoftCSharpCompiler.GetReferencesFromMonoDistribution()).Select <string, string>(new Func <string, string>(new MicrosoftCSharpCompiler.\u003CGetNETWSAAssemblies\u003Ec__AnonStoreyB3()
                {
                    monoAssemblyDirectory = BuildPipeline.GetMonoLibDirectory(BuildTarget.WSAPlayer)
                }.\u003C\u003Em__20C)).ToArray <string>());
            }
            if (wsaSDK != WSASDK.UWP)
            {
                return(Directory.GetFiles(MicrosoftCSharpCompiler.GetNETCoreFrameworkReferencesDirectory(wsaSDK), "*.dll"));
            }
            NuGetPackageResolver resolver = new NuGetPackageResolver()
            {
                ProjectLockFile = "UWP\\project.lock.json"
            };

            for (int index = !MicrosoftCSharpCompiler.EnsureProjectLockFile(resolver) ? 1 : 2; index != 0; --index)
            {
                try
                {
                    resolver.Resolve();
                }
                catch (Exception ex)
                {
                    if (index > 1)
                    {
                        Console.WriteLine("Failed to resolve NuGet packages. Deleting \"{0}\" and retrying.", (object)Path.GetFullPath(resolver.ProjectLockFile));
                        File.Delete(resolver.ProjectLockFile);
                        MicrosoftCSharpCompiler.EnsureProjectLockFile(resolver);
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            return(resolver.ResolvedReferences);
        }
        private Program StartCompilerImpl(List <string> arguments, string argsPrefix)
        {
            string[] references = this._island._references;
            for (int i = 0; i < references.Length; i++)
            {
                string fileName = references[i];
                arguments.Add("/reference:" + ScriptCompilerBase.PrepareFileName(fileName));
            }
            foreach (string current in this._island._defines.Distinct <string>())
            {
                arguments.Add("/define:" + current);
            }
            string[] files = this._island._files;
            for (int j = 0; j < files.Length; j++)
            {
                string fileName2 = files[j];
                arguments.Add(ScriptCompilerBase.PrepareFileName(fileName2).Replace('/', '\\'));
            }
            string text = Paths.Combine(new string[]
            {
                EditorApplication.applicationContentsPath,
                "Tools",
                "Roslyn",
                "CoreRun.exe"
            }).Replace('/', '\\');
            string text2 = Paths.Combine(new string[]
            {
                EditorApplication.applicationContentsPath,
                "Tools",
                "Roslyn",
                "csc.exe"
            }).Replace('/', '\\');

            if (!File.Exists(text))
            {
                MicrosoftCSharpCompiler.ThrowCompilerNotFoundException(text);
            }
            if (!File.Exists(text2))
            {
                MicrosoftCSharpCompiler.ThrowCompilerNotFoundException(text2);
            }
            base.AddCustomResponseFileIfPresent(arguments, "csc.rsp");
            string           text3 = CommandLineFormatter.GenerateResponseFile(arguments);
            ProcessStartInfo si    = new ProcessStartInfo
            {
                Arguments = string.Concat(new string[]
                {
                    "\"",
                    text2,
                    "\" ",
                    argsPrefix,
                    "@",
                    text3
                }),
                FileName       = text,
                CreateNoWindow = true
            };
            Program program = new Program(si);

            program.Start();
            return(program);
        }
        private void FillNETCoreCompilerOptions(WSASDK wsaSDK, List <string> arguments, ref string argsPrefix)
        {
            argsPrefix = "/noconfig ";
            arguments.Add("/nostdlib+");
            if (MicrosoftCSharpCompiler.GetCurrentScriptingBackend() != ScriptingImplementation.IL2CPP)
            {
                arguments.Add("/define:NETFX_CORE");
            }
            arguments.Add("/preferreduilang:en-US");
            string platformAssemblyPath = MicrosoftCSharpCompiler.GetPlatformAssemblyPath(wsaSDK);
            string str1;

            switch (wsaSDK)
            {
            case WSASDK.SDK80:
                str1 = "8.0";
                break;

            case WSASDK.SDK81:
                str1 = "8.1";
                break;

            case WSASDK.PhoneSDK81:
                str1 = "Phone 8.1";
                break;

            case WSASDK.UWP:
                str1 = "UAP";
                if (MicrosoftCSharpCompiler.GetCurrentScriptingBackend() != ScriptingImplementation.IL2CPP)
                {
                    arguments.Add("/define:WINDOWS_UWP");
                    break;
                }
                break;

            default:
                throw new Exception("Unknown Windows SDK: " + EditorUserBuildSettings.wsaSDK.ToString());
            }
            if (!File.Exists(platformAssemblyPath))
            {
                throw new Exception(string.Format("'{0}' not found, do you have Windows {1} SDK installed?", (object)platformAssemblyPath, (object)str1));
            }
            arguments.Add("/reference:\"" + platformAssemblyPath + "\"");
            string[] additionalReferences = MicrosoftCSharpCompiler.GetAdditionalReferences(wsaSDK);
            if (additionalReferences != null)
            {
                foreach (string str2 in additionalReferences)
                {
                    arguments.Add("/reference:\"" + str2 + "\"");
                }
            }
            foreach (string netwsaAssembly in this.GetNETWSAAssemblies(wsaSDK))
            {
                arguments.Add("/reference:\"" + netwsaAssembly + "\"");
            }
            if (MicrosoftCSharpCompiler.GetCurrentScriptingBackend() == ScriptingImplementation.IL2CPP)
            {
                return;
            }
            string path;
            string contents;
            string path2;

            switch (wsaSDK)
            {
            case WSASDK.SDK80:
                path     = Path.Combine(Path.GetTempPath(), ".NETCore,Version=v4.5.AssemblyAttributes.cs");
                contents = this.GetNetWSAAssemblyInfoWindows80();
                path2    = "Managed\\WinRTLegacy.dll";
                break;

            case WSASDK.SDK81:
                path     = Path.Combine(Path.GetTempPath(), ".NETCore,Version=v4.5.1.AssemblyAttributes.cs");
                contents = this.GetNetWSAAssemblyInfoWindows81();
                path2    = "Managed\\WinRTLegacy.dll";
                break;

            case WSASDK.PhoneSDK81:
                path     = Path.Combine(Path.GetTempPath(), "WindowsPhoneApp,Version=v8.1.AssemblyAttributes.cs");
                contents = this.GetNetWSAAssemblyInfoWindowsPhone81();
                path2    = "Managed\\Phone\\WinRTLegacy.dll";
                break;

            case WSASDK.UWP:
                path     = Path.Combine(Path.GetTempPath(), ".NETCore,Version=v5.0.AssemblyAttributes.cs");
                contents = this.GetNetWSAAssemblyInfoUWP();
                path2    = "Managed\\UAP\\WinRTLegacy.dll";
                break;

            default:
                throw new Exception("Unknown Windows SDK: " + EditorUserBuildSettings.wsaSDK.ToString());
            }
            string str3 = Path.Combine(BuildPipeline.GetPlaybackEngineDirectory(this._island._target, BuildOptions.None), path2);

            arguments.Add("/reference:\"" + str3.Replace('/', '\\') + "\"");
            if (File.Exists(path))
            {
                File.Delete(path);
            }
            File.WriteAllText(path, contents);
            arguments.Add(path);
        }
예제 #13
0
        private void FillNETCoreCompilerOptions(WSASDK wsaSDK, List <string> arguments, ref string argsPrefix)
        {
            argsPrefix = "/noconfig ";
            arguments.Add("/nostdlib+");
            if (MicrosoftCSharpCompiler.GetCurrentScriptingBackend() != ScriptingImplementation.IL2CPP)
            {
                arguments.Add("/define:NETFX_CORE");
            }
            arguments.Add("/preferreduilang:en-US");
            string platformAssemblyPath = MicrosoftCSharpCompiler.GetPlatformAssemblyPath(wsaSDK);

            switch (wsaSDK)
            {
            case WSASDK.SDK80:
            {
                string arg = "8.0";
                goto IL_BF;
            }

            case WSASDK.SDK81:
            {
                string arg = "8.1";
                goto IL_BF;
            }

            case WSASDK.PhoneSDK81:
            {
                string arg = "Phone 8.1";
                goto IL_BF;
            }

            case WSASDK.UWP:
            {
                string arg = "UAP";
                if (MicrosoftCSharpCompiler.GetCurrentScriptingBackend() != ScriptingImplementation.IL2CPP)
                {
                    arguments.Add("/define:WINDOWS_UWP");
                }
                goto IL_BF;
            }
            }
            throw new Exception("Unknown Windows SDK: " + EditorUserBuildSettings.wsaSDK.ToString());
IL_BF:
            if (!File.Exists(platformAssemblyPath))
            {
                string arg;
                throw new Exception(string.Format("'{0}' not found, do you have Windows {1} SDK installed?", platformAssemblyPath, arg));
            }
            arguments.Add("/reference:\"" + platformAssemblyPath + "\"");
            string[] additionalReferences = MicrosoftCSharpCompiler.GetAdditionalReferences(wsaSDK);
            if (additionalReferences != null)
            {
                string[] array = additionalReferences;
                for (int i = 0; i < array.Length; i++)
                {
                    string str = array[i];
                    arguments.Add("/reference:\"" + str + "\"");
                }
            }
            string[] nETWSAAssemblies = this.GetNETWSAAssemblies(wsaSDK);
            for (int j = 0; j < nETWSAAssemblies.Length; j++)
            {
                string str2 = nETWSAAssemblies[j];
                arguments.Add("/reference:\"" + str2 + "\"");
            }
            if (MicrosoftCSharpCompiler.GetCurrentScriptingBackend() != ScriptingImplementation.IL2CPP)
            {
                string text;
                string contents;
                string text2;
                switch (wsaSDK)
                {
                case WSASDK.SDK80:
                    text     = Path.Combine(Path.GetTempPath(), ".NETCore,Version=v4.5.AssemblyAttributes.cs");
                    contents = this.GetNetWSAAssemblyInfoWindows80();
                    text2    = "Managed\\WinRTLegacy.dll";
                    goto IL_263;

                case WSASDK.SDK81:
                    text     = Path.Combine(Path.GetTempPath(), ".NETCore,Version=v4.5.1.AssemblyAttributes.cs");
                    contents = this.GetNetWSAAssemblyInfoWindows81();
                    text2    = "Managed\\WinRTLegacy.dll";
                    goto IL_263;

                case WSASDK.PhoneSDK81:
                    text     = Path.Combine(Path.GetTempPath(), "WindowsPhoneApp,Version=v8.1.AssemblyAttributes.cs");
                    contents = this.GetNetWSAAssemblyInfoWindowsPhone81();
                    text2    = "Managed\\Phone\\WinRTLegacy.dll";
                    goto IL_263;

                case WSASDK.UWP:
                    text     = Path.Combine(Path.GetTempPath(), ".NETCore,Version=v5.0.AssemblyAttributes.cs");
                    contents = this.GetNetWSAAssemblyInfoUWP();
                    text2    = "Managed\\UAP\\WinRTLegacy.dll";
                    goto IL_263;
                }
                throw new Exception("Unknown Windows SDK: " + EditorUserBuildSettings.wsaSDK.ToString());
IL_263:
                text2 = Path.Combine(BuildPipeline.GetPlaybackEngineDirectory(this._island._target, BuildOptions.None), text2);
                arguments.Add("/reference:\"" + text2.Replace('/', '\\') + "\"");
                if (File.Exists(text))
                {
                    File.Delete(text);
                }
                File.WriteAllText(text, contents);
                arguments.Add(text);
            }
        }
예제 #14
0
 private string[] GetNETWSAAssemblies(WSASDK wsaSDK)
 {
     return(Directory.GetFiles(MicrosoftCSharpCompiler.GetNETCoreFrameworkReferencesDirectory(wsaSDK), "*.dll"));
 }
예제 #15
0
        private void FillNETCoreCompilerOptions(WSASDK wsaSDK, List <string> arguments, ref string argsPrefix)
        {
            argsPrefix = "/noconfig ";
            arguments.Add("/nostdlib+");
            arguments.Add("/define:NETFX_CORE");
            string platformAssemblyPath = MicrosoftCSharpCompiler.GetPlatformAssemblyPath(wsaSDK);
            string arg;

            switch (wsaSDK)
            {
            case WSASDK.SDK80:
                arg = "8.0";
                break;

            case WSASDK.SDK81:
                arg = "8.1";
                break;

            case WSASDK.PhoneSDK81:
                arg = "Phone 8.1";
                break;

            default:
                throw new Exception("Unknown Windows SDK: " + EditorUserBuildSettings.wsaSDK.ToString());
            }
            if (!File.Exists(platformAssemblyPath))
            {
                throw new Exception(string.Format("'{0}' not found, do you have Windows {1} SDK installed?", platformAssemblyPath, arg));
            }
            arguments.Add("/reference:\"" + platformAssemblyPath + "\"");
            string[] nETWSAAssemblies = this.GetNETWSAAssemblies(wsaSDK);
            for (int i = 0; i < nETWSAAssemblies.Length; i++)
            {
                string str = nETWSAAssemblies[i];
                arguments.Add("/reference:\"" + str + "\"");
            }
            string text;
            string contents;

            switch (wsaSDK)
            {
            case WSASDK.SDK80:
                text     = Path.Combine(Path.GetTempPath(), ".NETCore,Version=v4.5.AssemblyAttributes.cs");
                contents = this.GetNetWSAAssemblyInfoWindows80();
                break;

            case WSASDK.SDK81:
                text     = Path.Combine(Path.GetTempPath(), ".NETCore,Version=v4.5.1.AssemblyAttributes.cs");
                contents = this.GetNetWSAAssemblyInfoWindows81();
                break;

            case WSASDK.PhoneSDK81:
                text     = Path.Combine(Path.GetTempPath(), "WindowsPhoneApp,Version=v8.1.AssemblyAttributes.cs");
                contents = this.GetNetWSAAssemblyInfoWindowsPhone81();
                break;

            default:
                throw new Exception("Unknown Windows SDK: " + EditorUserBuildSettings.wsaSDK.ToString());
            }
            if (File.Exists(text))
            {
                File.Delete(text);
            }
            File.WriteAllText(text, contents);
            arguments.Add(text);
            string text2 = Path.Combine(BuildPipeline.GetPlaybackEngineDirectory(this._island._target, BuildOptions.None), "Managed\\WinRTLegacy.dll");

            arguments.Add("/reference:\"" + text2.Replace('/', '\\') + "\"");
        }