コード例 #1
0
ファイル: Program.cs プロジェクト: Youssef1313/Scaffolding
        // Creates a command to execute dotnet-aspnet-codegenerator-design
        private Command CreateDipatchCommand(
            IProjectContext context,
            string[] args,
            string buildBasePath,
            string configuration,
            NuGetFramework frameworkToUse,
            ScaffoldingServer server)
        {
            var projectDirectory = Directory.GetParent(context.ProjectFullPath).FullName;

            // Command Resolution Args
            // To invoke dotnet-aspnet-codegenerator-design with the user project's dependency graph,
            // we need to pass in the runtime config and deps file to dotnet for netcore app projects.
            // For projects that target net4x, since the dotnet-aspnet-codegenerator-design.exe is in the project's bin folder
            // and `dotnet build` generates a binding redirect file for it, we can directly invoke the exe from output location.

            var targetDir         = Path.GetDirectoryName(context.AssemblyFullPath);
            var runtimeConfigPath = Path.Combine(targetDir, context.RuntimeConfig);
            var depsFile          = Path.Combine(targetDir, context.DepsFile);

            string dotnetCodeGenInsideManPath = string.Empty;

            if (IsNetCoreAppFramework(frameworkToUse))
            {
                dotnetCodeGenInsideManPath = context.CompilationAssemblies
                                             .Where(c => Path.GetFileNameWithoutExtension(c.Name)
                                                    .Equals(DESIGN_TOOL_NAME, StringComparison.OrdinalIgnoreCase))
                                             .Select(reference => reference.ResolvedPath)
                                             .FirstOrDefault();
                if (string.IsNullOrEmpty(dotnetCodeGenInsideManPath))
                {
                    throw new InvalidOperationException(Resources.AddDesignPackage);
                }
            }
            else
            {
                dotnetCodeGenInsideManPath = Path.Combine(Path.GetDirectoryName(context.AssemblyFullPath), DESIGN_TOOL_NAME + ".exe");
                if (!File.Exists(dotnetCodeGenInsideManPath))
                {
                    throw new InvalidOperationException(Resources.AddDesignPackage);
                }
            }

            var dependencyArgs = ToolCommandLineHelper.GetProjectDependencyCommandArgs(
                args,
                frameworkToUse.GetShortFolderName(),
                server.Port.ToString());

            return(DotnetToolDispatcher.CreateDispatchCommand(
                       runtimeConfigPath: runtimeConfigPath,
                       depsFile: depsFile,
                       dependencyToolPath: dotnetCodeGenInsideManPath,
                       dispatchArgs: dependencyArgs,
                       framework: frameworkToUse,
                       configuration: configuration,
                       projectDirectory: projectDirectory,
                       assemblyFullPath: context.AssemblyFullPath)
                   .InWorkingDirectory(projectDirectory));
        }
コード例 #2
0
        private static int BuildAndDispatchDependencyCommand(
            string[] args,
            NuGetFramework frameworkToUse,
            string projectPath,
            string buildBasePath,
            string configuration)
        {
            if (frameworkToUse == null)
            {
                throw new ArgumentNullException(nameof(frameworkToUse));
            }
            if (string.IsNullOrEmpty(projectPath))
            {
                throw new ArgumentNullException(nameof(projectPath));
            }
            var buildResult = DotNetBuildCommandHelper.Build(
                projectPath,
                configuration,
                frameworkToUse,
                buildBasePath);

            if (buildResult.Result.ExitCode != 0)
            {
                //Build failed.
                // Stop the process here.
                _logger.LogMessage("Build Failed");
                _logger.LogMessage(string.Join(Environment.NewLine, buildResult.StdErr), LogMessageLevel.Error);
                return(buildResult.Result.ExitCode);
            }

            // Invoke the dependency command
            var projectFilePath = projectPath.EndsWith("project.json")
                ? projectPath
                : Path.Combine(projectPath, "project.json");

            var projectDirectory = Directory.GetParent(projectFilePath).FullName;

            var dependencyArgs = ToolCommandLineHelper.GetProjectDependencyCommandArgs(
                args,
                frameworkToUse.GetShortFolderName());

            var exitCode = DotnetToolDispatcher.CreateDispatchCommand(
                dependencyArgs,
                frameworkToUse,
                configuration,
                null,
                buildBasePath,
                projectDirectory)
                           .ForwardStdErr()
                           .ForwardStdOut()
                           .Execute()
                           .ExitCode;

            return(exitCode);
        }