Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADD] dotnet solution migrate #44419

Merged
merged 20 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from 18 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
19 changes: 10 additions & 9 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project>
<Import Project="$(RepositoryEngineeringDir)\dependabot\Packages.props" Condition="'$(RepositoryEngineeringDir)' != ''"/>
<Import Project="$(RepositoryEngineeringDir)\dependabot\Packages.props" Condition="'$(RepositoryEngineeringDir)' != ''" />
<PropertyGroup>
<!-- Using multiple feeds isn't supported by Maestro: https://github.com/dotnet/arcade/issues/14155. -->
<NoWarn>$(NoWarn);NU1507</NoWarn>
Expand All @@ -12,7 +12,7 @@
<PackageVersion Include="Microsoft.AspNetCore.DeveloperCertificates.XPlat" Version="$(MicrosoftAspNetCoreDeveloperCertificatesXPlatPackageVersion)" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Razor.Extensions.Tooling.Internal" Version="$(MicrosoftAspNetCoreMvcRazorExtensionsToolingInternalPackageVersion)" />
<PackageVersion Include="Microsoft.AspNetCore.TestHost" Version="$(MicrosoftAspNetCoreTestHostPackageVersion)" />
<PackageVersion Include="Microsoft.Bcl.AsyncInterfaces" Version="$(MicrosoftBclAsyncInterfacesPackageVersion)"/>
<PackageVersion Include="Microsoft.Bcl.AsyncInterfaces" Version="$(MicrosoftBclAsyncInterfacesPackageVersion)" />
<PackageVersion Include="Microsoft.Build.NuGetSdkResolver" Version="$(MicrosoftBuildNuGetSdkResolverPackageVersion)" />
<PackageVersion Include="Microsoft.CodeAnalysis" Version="$(MicrosoftCodeAnalysisPackageVersion)" />
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzer.Testing" Version="$(MicrosoftCodeAnalysisAnalyzerTestingVersion)" />
Expand Down Expand Up @@ -43,7 +43,7 @@
<PackageVersion Include="Microsoft.Extensions.Logging" Version="$(MicrosoftExtensionsLoggingVersion)" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="$(MicrosoftExtensionsLoggingAbstractionsVersion)" />
<PackageVersion Include="Microsoft.Extensions.Logging.Console" Version="$(MicrosoftExtensionsLoggingConsoleVersion)" />
<PackageVersion Include="Microsoft.Extensions.ObjectPool" Version="$(MicrosoftExtensionsObjectPoolPackageVersion)"/>
<PackageVersion Include="Microsoft.Extensions.ObjectPool" Version="$(MicrosoftExtensionsObjectPoolPackageVersion)" />
<PackageVersion Include="Microsoft.FSharp.Compiler" Version="$(MicrosoftFSharpCompilerPackageVersion)" />
<PackageVersion Include="Microsoft.IO.Redist" Version="$(MicrosoftIORedistPackageVersion)" />
<PackageVersion Include="Microsoft.Net.Compilers.Toolset.Framework" Version="$(MicrosoftNetCompilersToolsetFrameworkPackageVersion)" />
Expand All @@ -67,6 +67,7 @@
<PackageVersion Include="Microsoft.TestPlatform.CLI" Version="$(MicrosoftTestPlatformCLIPackageVersion)" />
<PackageVersion Include="Microsoft.VisualStudio.Composition" Version="17.4.16" />
<PackageVersion Include="Microsoft.VisualStudio.Setup.Configuration.Interop" Version="$(MicrosoftVisualStudioSetupConfigurationInteropVersion)" />
<PackageVersion Include="Microsoft.VisualStudio.SolutionPersistence" Version="1.0.9" />
<PackageVersion Include="Microsoft.Web.Deployment" Version="$(WebDeploymentPackageVersion)" />
<PackageVersion Include="Microsoft.Web.Xdt" Version="$(MicrosoftWebXdtPackageVersion)" />
<PackageVersion Include="Microsoft.Win32.SystemEvents" Version="$(MicrosoftWin32SystemEventsPackageVersion)" />
Expand Down Expand Up @@ -95,11 +96,11 @@
<PackageVersion Include="System.CommandLine" Version="$(SystemCommandLineVersion)" />
<PackageVersion Include="System.CommandLine.Rendering" Version="$(SystemCommandLineRenderingVersion)" />
<PackageVersion Include="System.ComponentModel.TypeConverter" Version="4.3.0" />
<PackageVersion Include="System.Composition.AttributedModel" Version="$(SystemCompositionAttributedModelPackageVersion)"/>
<PackageVersion Include="System.Composition.Convention" Version="$(SystemCompositionConventionPackageVersion)"/>
<PackageVersion Include="System.Composition.Hosting" Version="$(SystemCompositionHostingPackageVersion)"/>
<PackageVersion Include="System.Composition.Runtime" Version="$(SystemCompositionRuntimePackageVersion)"/>
<PackageVersion Include="System.Composition.TypedParts" Version="$(SystemCompositionTypedPartsPackageVersion)"/>
<PackageVersion Include="System.Composition.AttributedModel" Version="$(SystemCompositionAttributedModelPackageVersion)" />
<PackageVersion Include="System.Composition.Convention" Version="$(SystemCompositionConventionPackageVersion)" />
<PackageVersion Include="System.Composition.Hosting" Version="$(SystemCompositionHostingPackageVersion)" />
<PackageVersion Include="System.Composition.Runtime" Version="$(SystemCompositionRuntimePackageVersion)" />
<PackageVersion Include="System.Composition.TypedParts" Version="$(SystemCompositionTypedPartsPackageVersion)" />
<PackageVersion Include="System.Configuration.ConfigurationManager" Version="$(SystemConfigurationConfigurationManagerPackageVersion)" />
<PackageVersion Include="System.Formats.Asn1" Version="$(SystemFormatsAsn1Version)" />
<PackageVersion Include="System.IO.Hashing" Version="$(SystemIOHashingPackageVersion)" />
Expand All @@ -120,7 +121,7 @@
<PackageVersion Include="Valleysoft.DockerCredsProvider" Version="2.2.1" />
<PackageVersion Include="xunit" Version="$(XUnitVersion)" />
<PackageVersion Include="Xunit.Combinatorial" Version="$(XunitCombinatorialVersion)" />
<PackageVersion Include="xunit.console" Version="$(XUnitVersion)"/>
<PackageVersion Include="xunit.console" Version="$(XUnitVersion)" />
</ItemGroup>

<!-- Use different versions of Microsoft.Build.* depending on whether the output will be used in
edvilme marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
8 changes: 7 additions & 1 deletion src/Cli/dotnet/commands/dotnet-sln/LocalizableStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,10 @@
<data name="SolutionFolderHeader" xml:space="preserve">
<value>Solution Folder(s)</value>
</data>
</root>
<data name="MigrateAppFullName" xml:space="preserve">
<value>Generate a .slnx file from a .sln file.</value>
</data>
<data name="SlnxGenerated" xml:space="preserve">
<value>.slnx file {0} generated.</value>
</data>
</root>
25 changes: 25 additions & 0 deletions src/Cli/dotnet/commands/dotnet-sln/SlnCommandParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.CommandLine;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.Tools;
using NuGet.Packaging;
using LocalizableStrings = Microsoft.DotNet.Tools.Sln.LocalizableStrings;

Expand Down Expand Up @@ -37,10 +39,33 @@ private static CliCommand ConstructCommand()
command.Subcommands.Add(SlnAddParser.GetCommand());
command.Subcommands.Add(SlnListParser.GetCommand());
command.Subcommands.Add(SlnRemoveParser.GetCommand());
command.Subcommands.Add(SlnMigrateCommandParser.GetCommand());

command.SetAction((parseResult) => parseResult.HandleMissingCommand());

return command;
}

internal static string GetSlnFileFullPath(string slnFileOrDirectory)
{
if (File.Exists(slnFileOrDirectory))
{
return slnFileOrDirectory;
}
if (Directory.Exists(slnFileOrDirectory))
{
var files = Directory.GetFiles(slnFileOrDirectory, "*.sln", SearchOption.TopDirectoryOnly);
if (files.Length == 0)
{
throw new GracefulException(CommonLocalizableStrings.CouldNotFindSolutionIn, slnFileOrDirectory);
}
if (files.Length > 1)
{
throw new GracefulException(CommonLocalizableStrings.MoreThanOneSolutionInDirectory, slnFileOrDirectory);
}
return files.Single().ToString();
}
throw new GracefulException(CommonLocalizableStrings.CouldNotFindSolutionOrDirectory, slnFileOrDirectory);
}
}
}
58 changes: 58 additions & 0 deletions src/Cli/dotnet/commands/dotnet-sln/migrate/SlnMigrateCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections.Generic;
using System.CommandLine;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading.Tasks;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.Tools;
using Microsoft.VisualStudio.SolutionPersistence;
using Microsoft.VisualStudio.SolutionPersistence.Model;
using Microsoft.VisualStudio.SolutionPersistence.Serializer;
using LocalizableStrings = Microsoft.DotNet.Tools.Sln.LocalizableStrings;

namespace Microsoft.DotNet.Cli
{
internal class SlnMigrateCommand : CommandBase
edvilme marked this conversation as resolved.
Show resolved Hide resolved
{
private readonly string _slnFileOrDirectory;
private readonly IReporter _reporter;
public SlnMigrateCommand(
ParseResult parseResult,
IReporter reporter = null)
: base(parseResult)
{
_slnFileOrDirectory = Path.GetFullPath(parseResult.GetValue(SlnCommandParser.SlnArgument));
_reporter = reporter ?? Reporter.Output;
}

public override int Execute()
{
string slnFileFullPath = SlnCommandParser.GetSlnFileFullPath(_slnFileOrDirectory);
string slnxFileFullPath = Path.ChangeExtension(slnFileFullPath, "slnx");
Task task = ConvertToSlnxAsync(slnFileFullPath, slnxFileFullPath, CancellationToken.None);
if (task.IsCompletedSuccessfully)
{
return 0;
}
throw new GracefulException(task.Exception.Message, task.Exception);
edvilme marked this conversation as resolved.
Show resolved Hide resolved
}

private async Task ConvertToSlnxAsync(string filePath, string slnxFilePath, CancellationToken cancellationToken)
{
// See if the file is a known solution file.
ISolutionSerializer? serializer = SolutionSerializers.GetSerializerByMoniker(filePath);
if (serializer is null)
{
throw new GracefulException("Could not find serializer for file {0}", filePath);
}
SolutionModel solution = await serializer.OpenAsync(filePath, cancellationToken);
edvilme marked this conversation as resolved.
Show resolved Hide resolved
await SolutionSerializers.SlnXml.SaveAsync(slnxFilePath, solution, cancellationToken);
_reporter.WriteLine(LocalizableStrings.SlnxGenerated, slnxFilePath);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.CommandLine;
using Microsoft.DotNet.Tools.Sln.Add;
using LocalizableStrings = Microsoft.DotNet.Tools.Sln.LocalizableStrings;

namespace Microsoft.DotNet.Cli
{
public static class SlnMigrateCommandParser
{
private static readonly CliCommand Command = ConstructCommand();

public static CliCommand GetCommand()
{
return Command;
}

private static CliCommand ConstructCommand()
{
CliCommand command = new("migrate", LocalizableStrings.MigrateAppFullName);
edvilme marked this conversation as resolved.
Show resolved Hide resolved

command.Arguments.Add(SlnCommandParser.SlnArgument);

command.SetAction((parseResult) => new SlnMigrateCommand(parseResult).Execute());

return command;
}
}
}
10 changes: 10 additions & 0 deletions src/Cli/dotnet/commands/dotnet-sln/xlf/LocalizableStrings.cs.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/Cli/dotnet/commands/dotnet-sln/xlf/LocalizableStrings.de.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/Cli/dotnet/commands/dotnet-sln/xlf/LocalizableStrings.es.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/Cli/dotnet/commands/dotnet-sln/xlf/LocalizableStrings.fr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/Cli/dotnet/commands/dotnet-sln/xlf/LocalizableStrings.it.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/Cli/dotnet/commands/dotnet-sln/xlf/LocalizableStrings.ja.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/Cli/dotnet/commands/dotnet-sln/xlf/LocalizableStrings.ko.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/Cli/dotnet/commands/dotnet-sln/xlf/LocalizableStrings.pl.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading