diff --git a/dotnetcementrefs/FileUtilities.cs b/dotnetcementrefs/FileUtilities.cs
new file mode 100644
index 0000000..488952e
--- /dev/null
+++ b/dotnetcementrefs/FileUtilities.cs
@@ -0,0 +1,25 @@
+using System.IO;
+
+namespace dotnetcementrefs;
+
+internal static class FileUtilities
+{
+ public static string? GetDirectoryNameOfDirectoryAbove(string startingDirectory, string directoryName)
+ {
+ var lookInDirectory = Path.GetFullPath(startingDirectory);
+
+ do
+ {
+ var possibleDirectory = Path.Combine(lookInDirectory, directoryName);
+
+ if (Directory.Exists(possibleDirectory))
+ {
+ return lookInDirectory;
+ }
+
+ lookInDirectory = Path.GetDirectoryName(lookInDirectory);
+ } while (lookInDirectory != null);
+
+ return null;
+ }
+}
\ No newline at end of file
diff --git a/dotnetcementrefs/dotnetcementrefs.cs b/dotnetcementrefs/dotnetcementrefs.cs
index b5f807b..7eb1c1c 100644
--- a/dotnetcementrefs/dotnetcementrefs.cs
+++ b/dotnetcementrefs/dotnetcementrefs.cs
@@ -4,15 +4,16 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
+using Cement.Vostok.Devtools;
using Microsoft.Build.Construction;
-using Microsoft.Build.Definition;
using Microsoft.Build.Evaluation;
using NuGet.Common;
using NuGet.Configuration;
-using NuGet.Protocol;
using NuGet.Protocol.Core.Types;
using NuGet.Versioning;
+namespace dotnetcementrefs;
+
public static class Program
{
private static readonly Dictionary<(string package, bool includePrerelease, string[] sourceUrls), NuGetVersion> NugetCache = new();
@@ -105,6 +106,8 @@ private static async Task HandleProjectAsync(
return;
}
+ ReplaceModuleReferences(project);
+
var references = FindCementReferences(project, allProjectsInSolution, parameters.CementReferencePrefixes);
if (parameters.AllowLocalProjects)
{
@@ -151,6 +154,56 @@ private static async Task HandleProjectAsync(
await Console.Out.WriteLineAsync();
}
+ private static void ReplaceModuleReferences(Project project)
+ {
+ var moduleReferences = project.ItemsIgnoringCondition
+ .Where(item => item.ItemType == "ModuleReference")
+ .ToList();
+
+ if (moduleReferences.Count == 0)
+ {
+ return;
+ }
+
+ var workspacePath = FileUtilities.GetDirectoryNameOfDirectoryAbove(project.FullPath, ".cement");
+ if (workspacePath == null)
+ {
+ throw new($"Failed to find cement workspace for '{project.FullPath}'. " +
+ $"Make sure project is inside cement workspace.");
+ }
+
+ var moduleReferenceTransformer = new ModuleReferenceTransformer();
+
+ foreach (var moduleReference in moduleReferences)
+ {
+ try
+ {
+ var references = moduleReferenceTransformer
+ .ToReferences(workspacePath, moduleReference.EvaluatedInclude);
+
+ foreach (var reference in references)
+ {
+ if (moduleReference.Xml.Parent is ProjectItemGroupElement groupElement)
+ {
+ groupElement.AddItem("Reference", reference.Include, reference.Metadata);
+ }
+ else
+ {
+ project.AddItem("Reference", reference.Include, reference.Metadata);
+ }
+
+ project.RemoveItem(moduleReference);
+ }
+ }
+ catch (Exception e)
+ {
+ throw new($"Failed to replace ModuleReference at '{moduleReference.Xml.Location}'", e);
+ }
+ }
+
+ project.ReevaluateIfNecessary();
+ }
+
private static string[] GetUsePrereleaseForPrefixes(Project project)
{
var property = project.Properties.FirstOrDefault(x => x.Name == "DotnetCementRefsUsePrereleaseForPrefixes");
diff --git a/dotnetcementrefs/dotnetcementrefs.csproj b/dotnetcementrefs/dotnetcementrefs.csproj
index aa72763..6bcdea5 100644
--- a/dotnetcementrefs/dotnetcementrefs.csproj
+++ b/dotnetcementrefs/dotnetcementrefs.csproj
@@ -30,4 +30,8 @@
+
+
+
+
diff --git a/module.yaml b/module.yaml
index 4a144c8..2304b32 100644
--- a/module.yaml
+++ b/module.yaml
@@ -6,11 +6,14 @@ src:
full-build:
deps:
- vostok.devtools.ilrepack.bin
+ - idevops.cement.cli/vostok-devtools@v7.9.1
build:
target: None
configuration: None
dotnetcementrefs:
+ deps:
+ - idevops.cement.cli/vostok-devtools@v7.9.1
build:
- name: Build
tool: dotnet