Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ public FileSystemDotNetProjectBuildConfigReader(IJsonSerializer jsonSerializer)
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);
Expand Down Expand Up @@ -86,7 +87,7 @@ private GitRepository GetGitRepositoryUsingDirectory(string directoryPath)
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 !");
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.IO;
using System.Linq;
using System.Text;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
Expand Down Expand Up @@ -118,7 +119,7 @@ public string GetUsageInfo()

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]");
Expand Down Expand Up @@ -166,20 +167,21 @@ protected virtual string GetSolutionFile(CommandLineArgs commandLineArgs)
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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public string GetUsageInfo()

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("");
Expand Down Expand Up @@ -146,7 +146,8 @@ protected virtual string GetSolutionFile(CommandLineArgs commandLineArgs)
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,10 @@ protected async Task<ProjectBuildArgs> GetProjectBuildArgsAsync(CommandLineArgs

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);
Expand All @@ -190,15 +191,16 @@ protected async Task<ProjectBuildArgs> GetProjectBuildArgsAsync(CommandLineArgs
{
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)
{
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ private async Task GenerateCrudPageAsync(CommandLineArgs args)
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!");
}
Expand Down Expand Up @@ -476,7 +476,8 @@ void OpenSuiteInBrowserWithLaunchUrl()
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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private string GetWorkingDirectory(CommandLineArgs commandLineArgs)
return null;
}

if (path.EndsWith(".sln") || path.EndsWith(".csproj"))
if (path.EndsWith(".sln") || path.EndsWith(".slnx") || path.EndsWith(".csproj"))
{
return Path.GetDirectoryName(path);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ private async Task UpdateNugetPackages(CommandLineArgs commandLineArgs, string d
if (givenSolution.IsNullOrWhiteSpace())
{
solutions.AddRange(Directory.GetFiles(directory, "*.sln", SearchOption.AllDirectories));
solutions.AddRange(Directory.GetFiles(directory, "*.slnx", SearchOption.AllDirectories));
}
else
{
Expand All @@ -76,7 +77,7 @@ private async Task UpdateNugetPackages(CommandLineArgs commandLineArgs, string d
{
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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void MoveFiles(ProjectBuildContext context, string projectFolder, string

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}\""));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public override void Execute(ProjectBuildContext context)
}
}

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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
{
Expand Down Expand Up @@ -106,11 +177,14 @@ private string FindProjectKey(List<string> solutionFileLines)

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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ protected virtual string FindDefaultPassPhrase(ProjectBuildContext context)
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"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,8 @@ await _npmPackagesUpdater.Update(

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)
Expand Down Expand Up @@ -317,7 +318,8 @@ private string FindSolutionFolder(string projectFile)
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ protected virtual string FindSolutionFile(string projectFile)
{
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)
Expand All @@ -232,7 +233,8 @@ protected virtual string FindSolutionFolder(string projectFile)
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;
}
Expand Down
Loading
Loading