コード例 #1
0
        static string Resolve(RuntimeInfo runtime, string reference)
        {
            if (Path.IsPathRooted(reference) || File.Exists(reference))
            {
                return(reference);
            }

            var resolved = Path.Combine(runtime.RuntimeDir, reference);

            if (File.Exists(resolved))
            {
                return(resolved);
            }

            if (runtime.RuntimeFacadesDir != null && runtime.RuntimeFacadesDir != runtime.RuntimeDir)
            {
                resolved = Path.Combine(runtime.RuntimeFacadesDir, reference);
                if (File.Exists(resolved))
                {
                    return(resolved);
                }
            }

            return(reference);
        }
コード例 #2
0
        //attempt to resolve refs into the runtime dir if the host didn't already do so
        static string ResolveAssembly(RuntimeInfo runtime, string reference)
        {
            if (Path.IsPathRooted(reference) || File.Exists(reference))
            {
                return(reference);
            }

            var resolved = Path.Combine(runtime.RuntimeDir, reference);

            if (File.Exists(resolved))
            {
                return(resolved);
            }

            if (runtime.Kind != RuntimeKind.NetCore)
            {
                resolved = Path.Combine(runtime.RuntimeDir, "Facades", reference);
                if (File.Exists(resolved))
                {
                    return(resolved);
                }
            }

            return(reference);
        }
コード例 #3
0
        public static IEnumerable <string> GetResolvedReferences(RuntimeInfo runtime, List <string> references)
        {
            var asmFileNames = new HashSet <string> (
                references.Select(Path.GetFileName),
                StringComparer.OrdinalIgnoreCase
                );

            IEnumerable <string> GetImplicitReferences()
            {
                yield return("mscorlib.dll");

                yield return("netstandard.dll");

                if (runtime.Kind == RuntimeKind.NetCore)
                {
                    yield return("System.Runtime.dll");

                    //because we're referencing the impl not the ref asms, we end up
                    //having to ref internals
                    yield return("System.Private.CoreLib.dll");
                }
            }

            foreach (var asm in GetImplicitReferences())
            {
                if (!asmFileNames.Contains(asm))
                {
                    var asmPath = Path.Combine(runtime.RuntimeDir, asm);
                    if (File.Exists(asmPath))
                    {
                        yield return(Path.Combine(runtime.RuntimeDir, asm));
                    }
                }
            }

            foreach (var reference in references)
            {
                var asm = Resolve(runtime, reference);
                yield return(asm);
            }
        }
コード例 #4
0
 public static CSharpLangVersion GetBestSupportedLangVersion(RuntimeInfo runtime, CSharpLangVersion?compilerLangVersion = null)
 => (CSharpLangVersion)Math.Min((int)(compilerLangVersion ?? runtime.MaxSupportedLangVersion), (int)(runtime switch {
コード例 #5
0
        public static IEnumerable <string> GetResolvedReferences(RuntimeInfo runtime, List <string> references)
        {
            var asmFileNames = new HashSet <string> (StringComparer.OrdinalIgnoreCase);

            var disableRefAsms = Environment.GetEnvironmentVariable("T4_DEBUG_DISABLE_REF_ASMS") is string s && s switch {
                "true" => true,
                "y" => true,
                "yes" => true,
                "false" => false,
                "n" => false,
                "no" => false,
                _ => throw new Exception($"T4_DEBUG_DISABLE_REF_ASMS env var has unknown value '{s}'")
            };

            // if we have .NET Core reference assemblies, just reference all of them
            // as that's the behavior expected in .NET Core project files
            if (runtime.Kind == RuntimeKind.NetCore)
            {
                if (runtime.RefAssembliesDir != null && !disableRefAsms)
                {
                    foreach (var asm in Directory.EnumerateFiles(runtime.RefAssembliesDir, "*.dll"))
                    {
                        asmFileNames.Add(Path.GetFileName(asm));
                        yield return(asm);
                    }
                }
                else
                {
                    foreach (var knownFxAsm in KnownNet50RefAssemblyNames.Value)
                    {
                        var resolved = Path.Combine(runtime.RuntimeDir, knownFxAsm);
                        if (File.Exists(resolved))
                        {
                            asmFileNames.Add(knownFxAsm);
                            yield return(resolved);
                        }
                    }
                    //because we're referencing the impl not the ref asms, we end up having to ref internals
                    var corlib         = "System.Private.CoreLib.dll";
                    var resolvedCorlib = Path.Combine(runtime.RuntimeDir, corlib);
                    if (File.Exists(resolvedCorlib))
                    {
                        asmFileNames.Add(corlib);
                        yield return(resolvedCorlib);
                    }
                }

                // .NET Core doesn't include CompilerErrorCollection in the ref assemblies
                // so use the one we have loaded
                yield return(typeof(System.CodeDom.Compiler.CompilerErrorCollection).Assembly.Location);
            }
            else
            {
                // on full framework, automatically reference all the assemblies that an sdk-style net472 csproj would reference by default
                foreach (var asm in Net472DefaultAssemblyRefs.Value)
                {
                    var asmPath = Path.Combine(runtime.RuntimeDir, asm);
                    if (File.Exists(asmPath))
                    {
                        asmFileNames.Add(asm);
                        yield return(asmPath);
                    }
                }

                //also reference all the facades as MSBuild does this too
                foreach (var asm in Net472FacadeNames.Value)
                {
                    var asmPath = Path.Combine(runtime.RuntimeFacadesDir, asm);
                    if (File.Exists(asmPath))
                    {
                        asmFileNames.Add(asm);
                        yield return(asmPath);
                    }
                }
            }

            foreach (var reference in references)
            {
                if (!asmFileNames.Contains(Path.GetFileName(reference)))
                {
                    var asm = Resolve(runtime, reference);
                    yield return(asm);
                }
            }
        }
コード例 #6
0
ファイル: CscCodeCompiler.cs プロジェクト: nathansoz/t4
 public CscCodeCompiler(RuntimeInfo runtime)
 {
     this.runtime = runtime;
 }