当前位置: 首页>>代码示例>>C#>>正文


C# ProjectContext.GenerateBindingRedirects方法代码示例

本文整理汇总了C#中Microsoft.DotNet.ProjectModel.ProjectContext.GenerateBindingRedirects方法的典型用法代码示例。如果您正苦于以下问题:C# ProjectContext.GenerateBindingRedirects方法的具体用法?C# ProjectContext.GenerateBindingRedirects怎么用?C# ProjectContext.GenerateBindingRedirects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.DotNet.ProjectModel.ProjectContext的用法示例。


在下文中一共展示了ProjectContext.GenerateBindingRedirects方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CompileProject


//.........这里部分代码省略.........
                }

                Directory.CreateDirectory(refsFolder);
                foreach (var reference in references)
                {
                    File.Copy(reference, Path.Combine(refsFolder, Path.GetFileName(reference)));
                }
            }

            if (!AddNonCultureResources(context.ProjectFile, compilerArgs, intermediateOutputPath))
            {
                return false;
            }
            // Add project source files
            var sourceFiles = CompilerUtil.GetCompilationSources(context);
            compilerArgs.AddRange(sourceFiles);

            var compilerName = CompilerUtil.ResolveCompilerName(context);

            // Write RSP file
            var rsp = Path.Combine(intermediateOutputPath, $"dotnet-compile.{context.ProjectFile.Name}.rsp");
            File.WriteAllLines(rsp, compilerArgs);

            // Run pre-compile event
            var contextVariables = new Dictionary<string, string>()
            {
                { "compile:TargetFramework", context.TargetFramework.DotNetFrameworkName },
                { "compile:Configuration", args.ConfigValue },
                { "compile:OutputFile", outputName },
                { "compile:OutputDir", outputPath },
                { "compile:ResponseFile", rsp }
            };
            RunScripts(context, ScriptNames.PreCompile, contextVariables);

            var result = Command.Create($"dotnet-compile-{compilerName}", new string[] {"@" + $"{rsp}" })
                .OnErrorLine(line =>
                {
                    var diagnostic = ParseDiagnostic(context.ProjectDirectory, line);
                    if (diagnostic != null)
                    {
                        diagnostics.Add(diagnostic);
                    }
                    else
                    {
                        Reporter.Error.WriteLine(line);
                    }
                })
                .OnOutputLine(line =>
                {
                    var diagnostic = ParseDiagnostic(context.ProjectDirectory, line);
                    if (diagnostic != null)
                    {
                        diagnostics.Add(diagnostic);
                    }
                    else
                    {
                        Reporter.Output.WriteLine(line);
                    }
                }).Execute();

            // Run post-compile event
            contextVariables["compile:CompilerExitCode"] = result.ExitCode.ToString();
            RunScripts(context, ScriptNames.PostCompile, contextVariables);

            var success = result.ExitCode == 0;

            if (success)
            {
                success &= GenerateCultureResourceAssemblies(context.ProjectFile, dependencies, outputPath);
            }

            bool generateBindingRedirects = false;
            if (success && !args.NoHostValue && compilationOptions.EmitEntryPoint.GetValueOrDefault())
            {
                generateBindingRedirects = true;
                var rids = PlatformServices.Default.Runtime.GetAllCandidateRuntimeIdentifiers();
                var runtimeContext = ProjectContext.Create(context.ProjectDirectory, context.TargetFramework, rids);
                runtimeContext
                    .MakeCompilationOutputRunnable(outputPath, args.ConfigValue);
            }
            else if (!string.IsNullOrEmpty(context.ProjectFile.TestRunner))
            {
                generateBindingRedirects = true;
                var projectContext =
                    ProjectContext.Create(context.ProjectDirectory, context.TargetFramework,
                        new[] { PlatformServices.Default.Runtime.GetLegacyRestoreRuntimeIdentifier()});

                projectContext
                    .CreateExporter(args.ConfigValue)
                    .GetDependencies(LibraryType.Package)
                    .WriteDepsTo(Path.Combine(outputPath, projectContext.ProjectFile.Name + FileNameSuffixes.Deps));
            }

            if (generateBindingRedirects && context.TargetFramework.IsDesktop())
            {
                context.GenerateBindingRedirects(exporter, outputName);
            }

            return PrintSummary(diagnostics, sw, success);
        }
开发者ID:robmen,项目名称:dotnetcli,代码行数:101,代码来源:Program.cs


注:本文中的Microsoft.DotNet.ProjectModel.ProjectContext.GenerateBindingRedirects方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。