public static void CreateProjectFile(DotnetNewProjectType projectType, ProjectFilePath projectFilePath, DotnetNewConventions conventions, ILogger logger)
        {
            var projectDirectoryPath            = PathUtilities.GetDirectoryPath(projectFilePath).AsProjectDirectoryPath();
            var projectFileName                 = PathUtilities.GetFileName(projectFilePath).AsProjectFileName();
            var projectFileNameWithoutExtension = PathUtilities.GetFileNameWithoutExtension(projectFileName);
            var projectName = conventions.ProjectNameFromProjectFileNameWithoutExtension(projectFileNameWithoutExtension);

            var createdProjectFilePath = DotnetCommandServicesProvider.CreateProjectFile(projectType, projectName, projectDirectoryPath, logger);

            // Throw an exception if the solution file-path created by dotnet new is not the one we were expecting.
            if (createdProjectFilePath.Value != projectFilePath.Value)
            {
                throw new Exception($"Project creation file path mismatch.\nExpected: {projectFilePath}\nCreated: {createdProjectFilePath}");
            }
        }
        public static string ToDotnetCommandProjectType(this DotnetNewProjectType projectType)
        {
            switch (projectType)
            {
            case DotnetNewProjectType.Library:
                return("classlib");

            case DotnetNewProjectType.Console:
                return("console");

            case DotnetNewProjectType.MSTest:
                return("mstest");

            default:
                throw new ArgumentException(EnumHelper.UnexpectedEnumerationValueMessage(projectType));
            }
        }
        public static ProjectFilePath CreateProjectFile(DotnetNewProjectType projectType, ProjectName projectName, ProjectDirectoryPath projectDirectoryPath, ILogger logger)
        {
            var projectFilePath = Utilities.GetCSharpProjectFilePath(projectDirectoryPath, projectName);

            logger.LogDebug($"{projectName} - Creating project file:\n{projectFilePath}");

            var dotnetCommandProjectType = projectType.ToDotnetCommandProjectType();

            // Notes:
            //  --language: This is hard-coded to C#.
            //  --output: This must be the directory in which the solution file should be placed (tested).
            //  --name: This is the name of the solution, to which the .sln extension will be added. If .sln is suffixed to the name argument the resulting solution file will be .sln.sln!
            var arguments = $@"new {dotnetCommandProjectType} --language ""C#"" --output ""{projectDirectoryPath}"" --name {projectName}";

            ProcessRunner.Run(DotnetCommand.Value, arguments);

            logger.LogInformation($"{projectName} - Created project file:\n{projectFilePath}");

            return(projectFilePath);
        }
 /// <summary>
 /// Uses the <see cref="DotnetNewConventions.Instance"/>.
 /// </summary>
 public static void CreateProjectFile(DotnetNewProjectType projectType, ProjectFilePath projectFilePath, ILogger logger)
 {
     DotnetCommandServicesProvider.CreateProjectFile(projectType, projectFilePath, DotnetNewConventions.Instance, logger);
 }
 public static void CreateProjectFile(DotnetNewProjectType projectType, ProjectFilePath projectFilePath)
 {
     DotnetCommandServicesProvider.CreateProjectFile(projectType, projectFilePath, DummyLogger.Instance);
 }
Ejemplo n.º 6
0
 public void CreateProjectFile(DotnetNewProjectType projectType, ProjectFilePath projectFilePath)
 {
     DotnetCommandServicesProvider.CreateProjectFile(projectType, projectFilePath, this.Logger);
 }