Browse Source

Merge pull request #23916 from abpframework/auto-merge/rel-10-0/4032

Merge branch dev with rel-10.0
pull/23928/head
Ma Liming 8 months ago
committed by GitHub
parent
commit
ecfddb1d24
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 7
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Build/FileSystemDotNetProjectBuildConfigReader.cs
  2. 14
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/AddModuleCommand.cs
  3. 5
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/AddPackageCommand.cs
  4. 10
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/ProjectCreationCommandBase.cs
  5. 5
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SuiteCommand.cs
  6. 2
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SwitchToLocalCommand.cs
  7. 3
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/UpdateCommand.cs
  8. 2
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/AppNoLayersMoveProjectsStep.cs
  9. 2
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/ProjectRenameStep.cs
  10. 100
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/RemoveProjectFromSolutionStep.cs
  11. 3
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Templates/MicroserviceServiceStringEncryptionStep.cs
  12. 6
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackagePreviewSwitcher.cs
  13. 6
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/ProjectNugetPackageAdder.cs
  14. 202
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/SolutionFileModifier.cs
  15. 6
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/SolutionModuleAdder.cs

7
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Build/FileSystemDotNetProjectBuildConfigReader.cs

@ -21,8 +21,9 @@ public class FileSystemDotNetProjectBuildConfigReader : IDotNetProjectBuildConfi
public DotNetProjectBuildConfig Read(string directoryPath)
{
var buildConfig = new DotNetProjectBuildConfig();
var solutionFiles = Directory.GetFiles(directoryPath, "*.sln", SearchOption.TopDirectoryOnly);
if (solutionFiles.Length == 1)
var solutionFiles = Directory.GetFiles(directoryPath, "*.sln", SearchOption.TopDirectoryOnly)
.Concat(Directory.GetFiles(directoryPath, "*.slnx", SearchOption.TopDirectoryOnly)).ToList();
if (solutionFiles.Count == 1)
{
buildConfig.SlFilePath = solutionFiles.First();
var configFile = GetClosestFile(directoryPath, _buildConfigName);
@ -86,7 +87,7 @@ public class FileSystemDotNetProjectBuildConfigReader : IDotNetProjectBuildConfi
directoryInfo = directoryInfo.Parent;
} while (directoryInfo?.Parent != null);
throw new Exception("There is no solution file (*.sln) and " + _buildConfigName +
throw new Exception("There is no solution file (*.sln or *.slnx) and " + _buildConfigName +
" in the working directory and working directory is not a GIT repository !");
}

14
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/AddModuleCommand.cs

@ -1,5 +1,6 @@
using System;
using System.IO;
using System.Linq;
using System.Text;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
@ -118,7 +119,7 @@ public class AddModuleCommand : IConsoleCommand, ITransientDependency
sb.AppendLine("");
sb.AppendLine("'add-module' command is used to add a multi-package ABP module to a solution.");
sb.AppendLine("It should be used in a folder containing a .sln file.");
sb.AppendLine("It should be used in a folder containing a .sln or .slnx file.");
sb.AppendLine("");
sb.AppendLine("Usage:");
sb.AppendLine(" abp add-module <module-name> [options]");
@ -166,20 +167,21 @@ public class AddModuleCommand : IConsoleCommand, ITransientDependency
return providedSolutionFile;
}
var foundSolutionFiles = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.sln");
if (foundSolutionFiles.Length == 1)
var foundSolutionFiles = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.sln")
.Concat(Directory.GetFiles(Directory.GetCurrentDirectory(), "*.slnx")).ToList();
if (foundSolutionFiles.Count == 1)
{
return foundSolutionFiles[0];
}
if (foundSolutionFiles.Length == 0)
if (foundSolutionFiles.Count == 0)
{
throw new CliUsageException("'abp add-module' command should be used inside a folder containing a .sln file!");
throw new CliUsageException("'abp add-module' command should be used inside a folder containing a .sln or .slnx file!");
}
//foundSolutionFiles.Length > 1
var sb = new StringBuilder("There are multiple solution (.sln) files in the current directory. Please specify one of the files below:");
var sb = new StringBuilder("There are multiple solution (.sln or .slnx) files in the current directory. Please specify one of the files below:");
foreach (var foundSolutionFile in foundSolutionFiles)
{

5
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/AddPackageCommand.cs

@ -83,7 +83,7 @@ public class AddPackageCommand : IConsoleCommand, ITransientDependency
sb.AppendLine("");
sb.AppendLine("'add-package' command is used to add an ABP package to a project.");
sb.AppendLine("It should be used in a folder containing a .csproj file, .sln file or packages.json.");
sb.AppendLine("It should be used in a folder containing a .csproj file, .sln file, .slnx file or packages.json.");
sb.AppendLine("");
sb.AppendLine("Usage:");
sb.AppendLine("");
@ -146,7 +146,8 @@ public class AddPackageCommand : IConsoleCommand, ITransientDependency
return providedSolutionFile;
}
return Directory.GetFiles(Directory.GetCurrentDirectory(), "*.sln").FirstOrDefault();
return Directory.GetFiles(Directory.GetCurrentDirectory(), "*.sln")
.Concat(Directory.GetFiles(Directory.GetCurrentDirectory(), "*.slnx")).FirstOrDefault();
}
protected virtual string GetAngularDirectory(CommandLineArgs commandLineArgs)

10
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/ProjectCreationCommandBase.cs

@ -175,9 +175,10 @@ public abstract class ProjectCreationCommandBase
if (slnPath == null)
{
slnPath = Directory.GetFiles(outputFolderRoot, "*.sln").FirstOrDefault();
slnPath = Directory.GetFiles(outputFolderRoot, "*.sln")
.Concat(Directory.GetFiles(outputFolderRoot, "*.slnx")).FirstOrDefault();
}
else if (slnPath.EndsWith(".sln"))
else if (slnPath.EndsWith(".sln") || slnPath.EndsWith(".slnx"))
{
Directory.SetCurrentDirectory(Path.GetDirectoryName(slnPath));
outputFolderRoot = Path.GetDirectoryName(slnPath);
@ -190,7 +191,8 @@ public abstract class ProjectCreationCommandBase
{
Directory.SetCurrentDirectory(slnPath);
outputFolderRoot = slnPath;
slnPath = Directory.GetFiles(outputFolderRoot, "*.sln").FirstOrDefault();
slnPath = Directory.GetFiles(outputFolderRoot, "*.sln")
.Concat(Directory.GetFiles(outputFolderRoot, "*.slnx")).FirstOrDefault();
}
if (slnPath == null)
@ -198,7 +200,7 @@ public abstract class ProjectCreationCommandBase
throw new CliUsageException($"This command should be run inside a folder that contains a microservice solution! Or use -{Options.MainSolution.Short} parameter.");
}
var microserviceSolutionName = Path.GetFileName(slnPath).RemovePostFix(".sln");
var microserviceSolutionName = Path.GetFileName(slnPath).RemovePostFix(".slnx", ".sln");
version ??= SolutionPackageVersionFinder.FindByCsprojVersion(slnPath);
solutionName = SolutionName.Parse(microserviceSolutionName, projectName);

5
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SuiteCommand.cs

@ -119,7 +119,7 @@ public class SuiteCommand : IConsoleCommand, ITransientDependency
var solutionFile = args.Options.GetOrNull(Options.Crud.Solution.Short, Options.Crud.Solution.Long);
if (entityFile.IsNullOrEmpty() || !entityFile.EndsWith(".json") || !File.Exists(entityFile) ||
solutionFile.IsNullOrEmpty() || !solutionFile.EndsWith(".sln"))
solutionFile.IsNullOrEmpty() || !(solutionFile.EndsWith(".sln") || solutionFile.EndsWith(".slnx")))
{
throw new UserFriendlyException("Invalid Arguments!");
}
@ -476,7 +476,8 @@ public class SuiteCommand : IConsoleCommand, ITransientDependency
private object GetTargetSolutionOrNull(CommandLineArgs commandLineArgs)
{
return commandLineArgs.Options.GetOrNull(Options.Crud.Solution.Short, Options.Crud.Solution.Long)
?? Directory.GetFiles(Directory.GetCurrentDirectory(), "*.sln", SearchOption.TopDirectoryOnly).FirstOrDefault();
?? Directory.GetFiles(Directory.GetCurrentDirectory(), "*.sln", SearchOption.TopDirectoryOnly)
.Concat(Directory.GetFiles(Directory.GetCurrentDirectory(), "*.slnx", SearchOption.TopDirectoryOnly)).FirstOrDefault();
}
private Process StartSuite()

2
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SwitchToLocalCommand.cs

@ -70,7 +70,7 @@ public class SwitchToLocal : IConsoleCommand, ITransientDependency
return null;
}
if (path.EndsWith(".sln") || path.EndsWith(".csproj"))
if (path.EndsWith(".sln") || path.EndsWith(".slnx") || path.EndsWith(".csproj"))
{
return Path.GetDirectoryName(path);
}

3
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/UpdateCommand.cs

@ -64,6 +64,7 @@ public class UpdateCommand : IConsoleCommand, ITransientDependency
if (givenSolution.IsNullOrWhiteSpace())
{
solutions.AddRange(Directory.GetFiles(directory, "*.sln", SearchOption.AllDirectories));
solutions.AddRange(Directory.GetFiles(directory, "*.slnx", SearchOption.AllDirectories));
}
else
{
@ -76,7 +77,7 @@ public class UpdateCommand : IConsoleCommand, ITransientDependency
{
foreach (var solution in solutions)
{
var solutionName = Path.GetFileName(solution).RemovePostFix(".sln");
var solutionName = Path.GetFileName(solution).RemovePostFix(".slnx", ".sln");
await _nugetPackagesVersionUpdater.UpdateSolutionAsync(solution, checkAll: checkAll, version: version, leptonXVersion: leptonXVersion);

2
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/AppNoLayersMoveProjectsStep.cs

@ -41,7 +41,7 @@ public class AppNoLayersMoveProjectsStep : ProjectBuildPipelineStep
public void ModifySolutionFile(ProjectBuildContext context, string pathInSlnFile, string newPathInSlnFile)
{
var slnFile = context.Files.First(file => file.Name.EndsWith(".sln"));
var slnFile = context.Files.First(file => file.Name.EndsWith(".sln") ||file.Name.EndsWith(".slnx"));
slnFile.SetContent(slnFile.Content.Replace($"\"{pathInSlnFile}\"", $"\"{newPathInSlnFile}\""));
}

2
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/ProjectRenameStep.cs

@ -24,7 +24,7 @@ public class ProjectRenameStep : ProjectBuildPipelineStep
}
}
var files = context.Files.Where(f => f.Name.EndsWith(".sln") || f.Name.EndsWith(".cs"));
var files = context.Files.Where(f => f.Name.EndsWith(".sln") || f.Name.EndsWith(".slnx") || f.Name.EndsWith(".cs"));
foreach (var file in files)
{
file.NormalizeLineEndings();

100
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Building/Steps/RemoveProjectFromSolutionStep.cs

@ -1,49 +1,120 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Newtonsoft.Json;
using System.Xml;
using Newtonsoft.Json.Linq;
using Volo.Abp.Cli.ProjectBuilding.Files;
using Formatting = Newtonsoft.Json.Formatting;
namespace Volo.Abp.Cli.ProjectBuilding.Building.Steps;
public class RemoveProjectFromSolutionStep : ProjectBuildPipelineStep
{
private readonly string _projectName;
private string _solutionFilePath;
private string _solutionFilePathWithoutFileExtension;
private string _projectFolderPath;
private string ProjectNameWithQuotes => $"\"{_projectName}\"";
public RemoveProjectFromSolutionStep(
string projectName,
string solutionFilePath = null,
string solutionFilePathWithoutFileExtension = null,
string projectFolderPath = null)
{
_projectName = projectName;
_solutionFilePath = solutionFilePath;
_projectFolderPath = projectFolderPath;
if (solutionFilePathWithoutFileExtension != null && solutionFilePathWithoutFileExtension.EndsWith(".sln"))
{
_solutionFilePathWithoutFileExtension = solutionFilePathWithoutFileExtension.RemovePostFix(".sln");
}
if (solutionFilePathWithoutFileExtension != null && solutionFilePathWithoutFileExtension.EndsWith(".slnx"))
{
_solutionFilePathWithoutFileExtension = solutionFilePathWithoutFileExtension.RemovePostFix(".slnx");
}
else
{
_solutionFilePathWithoutFileExtension = solutionFilePathWithoutFileExtension;
}
}
public override void Execute(ProjectBuildContext context)
{
SetSolutionAndProjectPathsIfNull(context);
if (_solutionFilePath == null || _projectFolderPath == null)
if (_solutionFilePathWithoutFileExtension == null || _projectFolderPath == null)
{
return;
}
new RemoveFolderStep(_projectFolderPath).Execute(context);
var solutionFile = context.GetFile(_solutionFilePath);
solutionFile.NormalizeLineEndings();
solutionFile.SetLines(RemoveProject(solutionFile.GetLines().ToList()));
var solutionFile = context.FindFile(_solutionFilePathWithoutFileExtension + ".sln")
?? context.GetFile(_solutionFilePathWithoutFileExtension + ".slnx");
if (solutionFile.Name.EndsWith(".sln"))
{
RemoveProjectFromSlnFile(solutionFile);
}
else
{
RemoveProjectFromSlnxFile(solutionFile);
}
RemoveProjectFromAbpmdlFile(context);
}
private void RemoveProjectFromSlnxFile(FileEntry solutionFile)
{
var document = new XmlDocument { PreserveWhitespace = true };
document.LoadXml(solutionFile.Content);
var projectNodes = document.SelectNodes("//Project");
if (projectNodes == null || projectNodes.Count < 1)
{
return;
}
var nodesToBeRemoved = new List<XmlNode>();
foreach (XmlNode projectNode in projectNodes)
{
var pathAttr = projectNode.Attributes?["Path"]?.Value;
if (string.IsNullOrWhiteSpace(pathAttr))
{
continue;
}
var normalized = pathAttr.Replace('\\', '/');
var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(normalized);
if (string.Equals(fileNameWithoutExtension, _projectName, StringComparison.OrdinalIgnoreCase))
{
nodesToBeRemoved.Add(projectNode);
}
}
foreach (var node in nodesToBeRemoved)
{
node.ParentNode!.RemoveChild(node);
}
solutionFile.SetContent(
document.OuterXml
.SplitToLines()
.Where(x=> !x.Trim().Equals(string.Empty))
.JoinAsString(Environment.NewLine));
}
private void RemoveProjectFromSlnFile(FileEntry solutionFile)
{
solutionFile.NormalizeLineEndings();
solutionFile.SetLines(RemoveProject(solutionFile.GetLines().ToList()));
}
private void RemoveProjectFromAbpmdlFile(ProjectBuildContext context)
{
var abpmdlFile = context.FindFile(_solutionFilePath.RemovePostFix(".sln") + ".abpmdl");
var abpmdlFile = context.FindFile(_solutionFilePathWithoutFileExtension + ".abpmdl");
if (abpmdlFile == null)
{
@ -106,11 +177,14 @@ public class RemoveProjectFromSolutionStep : ProjectBuildPipelineStep
private void SetSolutionAndProjectPathsIfNull(ProjectBuildContext context)
{
if (_solutionFilePath == null)
if (_solutionFilePathWithoutFileExtension == null)
{
_solutionFilePath = context.FindFile("/aspnet-core/MyCompanyName.MyProjectName.sln")?.Name ??
context.FindFile("/MyCompanyName.MyProjectName.sln")?.Name ??
context.FindFile("/MyCompanyName.MyProjectName.MicroserviceName.sln")?.Name;
_solutionFilePathWithoutFileExtension = context.FindFile("/aspnet-core/MyCompanyName.MyProjectName.sln")?.Name.RemovePostFix(".sln") ??
context.FindFile("/aspnet-core/MyCompanyName.MyProjectName.slnx")?.Name.RemovePostFix(".slnx") ??
context.FindFile("/MyCompanyName.MyProjectName.sln")?.Name.RemovePostFix(".sln") ??
context.FindFile("/MyCompanyName.MyProjectName.slnx")?.Name.RemovePostFix(".slnx") ??
context.FindFile("/MyCompanyName.MyProjectName.MicroserviceName.sln")?.Name.RemovePostFix(".sln") ??
context.FindFile("/MyCompanyName.MyProjectName.MicroserviceName.slnx")?.Name.RemovePostFix(".slnx");
}
if (_projectFolderPath == null)
{

3
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectBuilding/Templates/MicroserviceServiceStringEncryptionStep.cs

@ -17,7 +17,8 @@ public class MicroserviceServiceStringEncryptionStep : RandomizeStringEncryption
var directoryInfo = new DirectoryInfo(context.BuildArgs.OutputFolder);
do
{
var msSolution = Directory.GetFiles(directoryInfo.FullName, "*.sln", SearchOption.TopDirectoryOnly).FirstOrDefault();
var msSolution = Directory.GetFiles(directoryInfo.FullName, "*.sln", SearchOption.TopDirectoryOnly)
.Concat(Directory.GetFiles(directoryInfo.FullName, "*.slnx", SearchOption.TopDirectoryOnly)).FirstOrDefault();
if (msSolution != null)
{
var appSettings = Directory.GetFiles(Path.Combine(directoryInfo.FullName, "apps", "auth-server"),

6
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/PackagePreviewSwitcher.cs

@ -269,7 +269,8 @@ public class PackagePreviewSwitcher : ITransientDependency
private List<string> GetSolutionPaths(CommandLineArgs commandLineArgs)
{
return Directory.GetFiles(GetDirectory(commandLineArgs), "*.sln", SearchOption.AllDirectories).ToList();
return Directory.GetFiles(GetDirectory(commandLineArgs), "*.sln", SearchOption.AllDirectories)
.Concat(Directory.GetFiles(GetDirectory(commandLineArgs), "*.slnx", SearchOption.AllDirectories)).ToList();
}
private List<string> GetProjectPaths(CommandLineArgs commandLineArgs)
@ -317,7 +318,8 @@ public class PackagePreviewSwitcher : ITransientDependency
return Path.GetDirectoryName(projectFile);
}
if (Directory.GetFiles(targetFolder, "*.sln", SearchOption.TopDirectoryOnly).Any())
if (Directory.GetFiles(targetFolder, "*.sln", SearchOption.TopDirectoryOnly)
.Concat(Directory.GetFiles(targetFolder, "*.slnx", SearchOption.TopDirectoryOnly)).Any())
{
break;
}

6
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/ProjectNugetPackageAdder.cs

@ -214,7 +214,8 @@ public class ProjectNugetPackageAdder : ITransientDependency
{
var folder = FindSolutionFolder(projectFile);
return Directory.GetFiles(folder, "*.sln", SearchOption.TopDirectoryOnly).FirstOrDefault();
return Directory.GetFiles(folder, "*.sln", SearchOption.TopDirectoryOnly)
.Concat(Directory.GetFiles(folder, "*.slnx", SearchOption.TopDirectoryOnly)).FirstOrDefault();
}
protected virtual string FindSolutionFolder(string projectFile)
@ -232,7 +233,8 @@ public class ProjectNugetPackageAdder : ITransientDependency
return Path.GetDirectoryName(projectFile);
}
if (Directory.GetFiles(targetFolder, "*.sln", SearchOption.TopDirectoryOnly).Any())
if (Directory.GetFiles(targetFolder, "*.sln", SearchOption.TopDirectoryOnly)
.Concat(Directory.GetFiles(targetFolder, "*.slnx", SearchOption.TopDirectoryOnly)).Any())
{
break;
}

202
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/SolutionFileModifier.cs

@ -4,34 +4,31 @@ using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using Volo.Abp.Cli.Utils;
using Volo.Abp.DependencyInjection;
namespace Volo.Abp.Cli.ProjectModification;
public class SolutionFileModifier : ITransientDependency
{
public static Encoding DefaultEncoding = Encoding.UTF8;
private readonly ICmdHelper _cmdHelper;
public SolutionFileModifier(ICmdHelper cmdHelper)
{
_cmdHelper = cmdHelper;
}
public async Task RemoveProjectFromSolutionFileAsync(string solutionFile, string projectName)
{
using (var fileStream = File.Open(solutionFile, FileMode.Open, FileAccess.ReadWrite, FileShare.None))
var list = _cmdHelper.RunCmdAndGetOutput($"dotnet sln \"{solutionFile}\" list");
foreach (var line in list.Split(new[] { Environment.NewLine, "\n" }, StringSplitOptions.None))
{
using (var sr = new StreamReader(fileStream, Encoding.Default, true))
if (Path.GetFileNameWithoutExtension(line.Trim()).Equals(projectName, StringComparison.InvariantCultureIgnoreCase))
{
var solutionFileContent = await sr.ReadToEndAsync();
solutionFileContent.NormalizeLineEndings();
var lines = solutionFileContent.Split(new[] { Environment.NewLine, "\n" }, StringSplitOptions.None);
var updatedContent = RemoveProject(lines.ToList(), projectName).JoinAsString(Environment.NewLine);
fileStream.Seek(0, SeekOrigin.Begin);
fileStream.SetLength(0);
using (var sw = new StreamWriter(fileStream, DefaultEncoding))
{
await sw.WriteAsync(updatedContent);
await sw.FlushAsync();
}
_cmdHelper.RunCmd($"dotnet sln \"{solutionFile}\" remove \"{line.Trim()}\"");
break;
}
}
}
@ -48,105 +45,16 @@ public class SolutionFileModifier : ITransientDependency
private async Task AddPackageAsync(NugetPackageInfo package, string solutionFile)
{
var srcFolderId = await AddNewFolderAndGetIdOrGetExistingIdAsync(solutionFile, "src");
var solutionFileContent = File.ReadAllText(solutionFile);
var lines = solutionFileContent.Split(new[] { Environment.NewLine, "\n" }, StringSplitOptions.None).ToList();
if (lines.Any(l => l.Contains($"\"{package.Name}\"")))
{
return;
}
var projectGuid = Guid.NewGuid().ToString();
var newProjectLine = "Project(\"{9A19103F-16F7-4668-BE54-9A1E7A4F7556}\") = \"" + package.Name + "\"," +
" \"packages\\" + package.Name + "\\" +
"\\" + package.Name + ".csproj\", \"{" + projectGuid + "}\""
+ Environment.NewLine + "EndProject";
lines.InsertAfter(l => l.Trim().Equals("EndProject"), newProjectLine);
var newPostSolutionLine =
" {" + projectGuid + "}.Debug|Any CPU.ActiveCfg = Debug|Any CPU" + Environment.NewLine +
" {" + projectGuid + "}.Debug|Any CPU.Build.0 = Debug|Any CPU" + Environment.NewLine +
" {" + projectGuid + "}.Release|Any CPU.ActiveCfg = Release|Any CPU" + Environment.NewLine +
" {" + projectGuid + "}.Release|Any CPU.Build.0 = Release|Any CPU";
lines.InsertAfter(l => l.Contains("GlobalSection") && l.Contains("ProjectConfigurationPlatforms"),
newPostSolutionLine);
var newPreSolutionLine =
" {" + projectGuid + "} = {" + srcFolderId + "}";
lines.InsertAfter(l => l.Contains("GlobalSection") && l.Contains("NestedProjects"), newPreSolutionLine);
File.WriteAllText(solutionFile, string.Join(Environment.NewLine, lines), DefaultEncoding);
}
private List<string> RemoveProject(List<string> solutionFileLines, string projectName)
{
var projectKey = FindProjectKey(solutionFileLines, projectName);
if (projectKey == null)
{
return solutionFileLines;
}
var newSolutionFileLines = new List<string>();
var firstOccurence = true;
for (var i = 0; i < solutionFileLines.Count; ++i)
{
if (solutionFileLines[i].Contains(projectKey))
{
if (firstOccurence)
{
firstOccurence = false;
++i; //Skip "EndProject" line too.
}
continue;
}
newSolutionFileLines.Add(solutionFileLines[i]);
}
return newSolutionFileLines;
}
private string FindProjectKey(List<string> solutionFileLines, string projectName)
{
var projectNameWithQuotes = $"\"{projectName}\"";
foreach (var solutionFileLine in solutionFileLines)
{
if (solutionFileLine.Contains(projectNameWithQuotes))
{
var curlyBracketStartIndex = solutionFileLine.LastIndexOf("{", StringComparison.OrdinalIgnoreCase);
var curlyBracketEndIndex = solutionFileLine.LastIndexOf("}", StringComparison.OrdinalIgnoreCase);
return solutionFileLine.Substring(curlyBracketStartIndex + 1,
curlyBracketEndIndex - curlyBracketStartIndex - 1);
}
}
return null;
_cmdHelper.RunCmd($"dotnet sln \"{solutionFile}\" add \"packages\\{package.Name}\\{package.Name}.csproj\" --solution-folder src");
}
private async Task AddModuleAsync(ModuleWithMastersInfo module, string solutionFile)
{
var srcModuleFolderId = await AddNewFolderAndGetIdOrGetExistingIdAsync(solutionFile, module.Name,
await AddNewFolderAndGetIdOrGetExistingIdAsync(solutionFile, "modules"));
var testModuleFolderId = await AddNewFolderAndGetIdOrGetExistingIdAsync(solutionFile, module.Name + ".Tests",
await AddNewFolderAndGetIdOrGetExistingIdAsync(solutionFile, "test"));
var file = File.ReadAllText(solutionFile);
var lines = file.Split(new[] { Environment.NewLine, "\n" }, StringSplitOptions.None).ToList();
var projectsUnderModule = Directory.GetFiles(
Path.Combine(Path.GetDirectoryName(solutionFile), "modules", module.Name),
"*.csproj",
SearchOption.AllDirectories);
var projectsUnderTest = new List<string>();
if (Directory.Exists(Path.Combine(Path.GetDirectoryName(solutionFile), "modules", module.Name, "test")))
{
@ -158,41 +66,14 @@ public class SolutionFileModifier : ITransientDependency
foreach (var projectPath in projectsUnderModule)
{
var parentFolderId = projectsUnderTest.Contains(projectPath) ? testModuleFolderId : srcModuleFolderId;
var projectId = Path.GetFileName(projectPath).Replace(".csproj", "");
var projectParentFolderInModule = projectsUnderTest.Contains(projectPath) ? "test" : "src";
if (lines.Any(l => l.Contains($"\"{projectId}\"")))
{
continue;
}
var projectGuid = Guid.NewGuid().ToString();
var newProjectLine = "Project(\"{9A19103F-16F7-4668-BE54-9A1E7A4F7556}\") = \"" + projectId + "\"," +
" \"modules\\" + module.Name + "\\" + projectParentFolderInModule + "\\" +
projectId + "\\" + projectId + ".csproj\", \"{" + projectGuid + "}\""
+ Environment.NewLine + "EndProject";
lines.InsertAfter(l => l.Trim().Equals("EndProject"), newProjectLine);
var folder = projectsUnderTest.Contains(projectPath) ? "test" : "src";
var newPostSolutionLine =
" {" + projectGuid + "}.Debug|Any CPU.ActiveCfg = Debug|Any CPU" + Environment.NewLine +
" {" + projectGuid + "}.Debug|Any CPU.Build.0 = Debug|Any CPU" + Environment.NewLine +
" {" + projectGuid + "}.Release|Any CPU.ActiveCfg = Release|Any CPU" + Environment.NewLine +
" {" + projectGuid + "}.Release|Any CPU.Build.0 = Release|Any CPU";
lines.InsertAfter(l => l.Contains("GlobalSection") && l.Contains("ProjectConfigurationPlatforms"),
newPostSolutionLine);
var newPreSolutionLine =
" {" + projectGuid + "} = {" + parentFolderId + "}";
lines.InsertAfter(l => l.Contains("GlobalSection") && l.Contains("NestedProjects"), newPreSolutionLine);
var projectId = Path.GetFileName(projectPath).Replace(".csproj", "");
var package = @$"modules\{module.Name}\{folder}\{projectId}\{projectId}.csproj";
_cmdHelper.RunCmd($"dotnet sln \"{solutionFile}\" add \"{package}\" --solution-folder {folder}");
}
File.WriteAllText(solutionFile, string.Join(Environment.NewLine, lines), Encoding.UTF8);
if (module.MasterModuleInfos != null)
{
foreach (var masterModule in module.MasterModuleInfos)
@ -201,43 +82,4 @@ public class SolutionFileModifier : ITransientDependency
}
}
}
private async Task<string> AddNewFolderAndGetIdOrGetExistingIdAsync(string solutionFile, string folderName,
string parentFolderId = null)
{
var file = File.ReadAllText(solutionFile);
var lines = file.Split(new[] { Environment.NewLine, "\n" }, StringSplitOptions.None).ToList();
string folderId;
var folderLineIndex = lines.FindIndex(l =>
l.Contains("2150E333-8FDC-42A3-9474-1A3956D46DE8") && l.Contains("\"" + folderName + "\""));
if (folderLineIndex < 0)
{
folderId = Guid.NewGuid().ToString();
var newFolderLine = "Project(\"{2150E333-8FDC-42A3-9474-1A3956D46DE8}\") = \"" + folderName + "\", \"" +
folderName + "\", \"{" + folderId + "}\""
+ Environment.NewLine + "EndProject";
lines.InsertAfter(l => l.Trim().Equals("EndProject"), newFolderLine);
if (parentFolderId != null)
{
var newPreSolutionLine =
" {" + folderId + "} = {" + parentFolderId + "}";
lines.InsertAfter(l => l.Contains("GlobalSection") && l.Contains("NestedProjects"),
newPreSolutionLine);
}
}
else
{
folderId = lines[folderLineIndex].Replace("\"", " ").Replace("{", " ").Replace("}", " ").TrimEnd()
.Split(" ").Last();
}
File.WriteAllText(solutionFile, string.Join(Environment.NewLine, lines), Encoding.UTF8);
return folderId;
}
}

6
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ProjectModification/SolutionModuleAdder.cs

@ -335,7 +335,8 @@ public class SolutionModuleAdder : ITransientDependency
{
var projectsToRemove = new List<string>();
var moduleDirectory = Path.Combine(solutionDirectory, "modules", module.Name);
var moduleSolutionFile = Directory.GetFiles(moduleDirectory, "*.sln", SearchOption.TopDirectoryOnly).First();
var moduleSolutionFile = Directory.GetFiles(moduleDirectory, "*.sln", SearchOption.TopDirectoryOnly)
.Concat(Directory.GetFiles(moduleDirectory, "*.slnx", SearchOption.TopDirectoryOnly)).First();
var isProjectTiered = await IsProjectTiered(projectFiles);
var webPackagesWillBeAddedToBlazorServerProject = false;
@ -609,7 +610,8 @@ public class SolutionModuleAdder : ITransientDependency
private async Task DeleteRedundantHostProjects(string targetModuleFolder, string folderName)
{
var moduleSolutionFile = Directory.GetFiles(targetModuleFolder, "*.sln", SearchOption.TopDirectoryOnly).First();
var moduleSolutionFile = Directory.GetFiles(targetModuleFolder, "*.sln", SearchOption.TopDirectoryOnly)
.Concat(Directory.GetFiles(targetModuleFolder, "*.slnx", SearchOption.TopDirectoryOnly)).First();
var folder = Path.Combine(targetModuleFolder, folderName);
if (Directory.Exists(folder))

Loading…
Cancel
Save