Exemple #1
0
        // 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));
        }
Exemple #2
0
 private ScaffoldingServer StartServer(ILogger logger, IProjectContext projectInformation)
 {
     server = ScaffoldingServer.Listen(logger);
     server.AddHandler(new ProjectInformationMessageHandler(projectInformation, logger));
     server.AddHandler(new FileSystemChangeMessageHandler(logger));
     server.Accept();
     return(server);
 }