diff --git a/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Modifying/CsprojFileManager.cs b/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Modifying/CsprojFileManager.cs index 61a7d0c084..2d8ac43edc 100644 --- a/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Modifying/CsprojFileManager.cs +++ b/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Modifying/CsprojFileManager.cs @@ -72,6 +72,37 @@ namespace Volo.Abp.Studio.Packages.Modifying await SaveXmlDocumentAsync(filePath, document); } + public async Task ConvertPackageReferenceToProjectReferenceAsync(string filePath, string projectToReference) + { + var document = await GetXmlDocumentAsync(filePath); + + var packageName = Path.GetFileName(projectToReference).RemovePostFix(".csproj"); + + var matchedNodes = document.SelectNodes($"/Project/ItemGroup/PackageReference[starts-with(@Include, '{packageName}')]"); + + if (matchedNodes.Count == 0) + { + return; + } + + var targetNode = matchedNodes[0]; + var targetNodeParent = targetNode.ParentNode; + + targetNodeParent.RemoveChild(targetNode); + + var relativePath = PathHelper.GetRelativePath(filePath, projectToReference); + + var newNode = document.CreateElement("ProjectReference"); + + var includeAttr = document.CreateAttribute("Include"); + includeAttr.Value = relativePath; + newNode.Attributes.Append(includeAttr); + + targetNodeParent.AppendChild(newNode); + + await SaveXmlDocumentAsync(filePath, document); + } + private XmlNode GetOrCreateItemGroupNode(XmlDocument document) { var nodes = document["Project"].SelectNodes("ItemGroup"); diff --git a/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Modifying/ICsprojFileManager.cs b/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Modifying/ICsprojFileManager.cs index 29aa3f34b3..5a9b0e4c4c 100644 --- a/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Modifying/ICsprojFileManager.cs +++ b/studio/src/Volo.Abp.Studio.Domain.CommonServices/Volo/Abp/Studio/Modifying/ICsprojFileManager.cs @@ -7,5 +7,7 @@ namespace Volo.Abp.Studio.Packages.Modifying Task AddProjectReferenceAsync(string filePath, string projectToReference); Task AddPackageReferenceAsync(string filePath, string packageName, string version); + + Task ConvertPackageReferenceToProjectReferenceAsync(string filePath, string projectToReference); } }