-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit of console application
- Loading branch information
Showing
10 changed files
with
603 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6" /> | ||
</startup> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using NuGet.Packaging.Core; | ||
using System.Text.RegularExpressions; | ||
|
||
namespace ConsoleApp | ||
{ | ||
internal class AssemblyReferenceRegularExpressions : RegularExpressionsForPackagesBase | ||
{ | ||
protected override Regex GetRegularExpression(PackageIdentity packageIdentity) | ||
{ | ||
return new Regex($@".*{Regex.Escape(packageIdentity.Id)}\.{Regex.Escape(packageIdentity.Version.ToString())}\\.+", RegexOptions.IgnoreCase); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{1FE13D69-D7BE-44D9-96ED-190E7D379704}</ProjectGuid> | ||
<OutputType>Exe</OutputType> | ||
<RootNamespace>ConsoleApp</RootNamespace> | ||
<AssemblyName>PackagesConfigProjectConverter</AssemblyName> | ||
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Net.Http" /> | ||
<Reference Include="System.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="AssemblyReferenceRegularExpressions.cs" /> | ||
<Compile Include="ExtensionsMethods.cs" /> | ||
<Compile Include="ImportRegularExpressions.cs" /> | ||
<Compile Include="Program.cs" /> | ||
<Compile Include="ProjectConverter.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
<Compile Include="RegularExpressionsForPackagesBase.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="App.config" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Build"> | ||
<Version>15.3.409</Version> | ||
</PackageReference> | ||
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers"> | ||
<Version>1.1.0</Version> | ||
</PackageReference> | ||
<PackageReference Include="NuGet.Commands"> | ||
<Version>4.4.0</Version> | ||
</PackageReference> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace ConsoleApp | ||
{ | ||
internal static class ExtensionsMethods | ||
{ | ||
private static readonly char[] ArgumentValueSeparators = { ';', ',' }; | ||
private static readonly char[] ArgumentNameSeparators = { ':' }; | ||
|
||
public static IEnumerable<string> GetCommandLineArgumentValues(this string[] args, params string[] argumentNames) | ||
{ | ||
foreach (string arg in args.Where(i => argumentNames.Any(x => i.StartsWith(x, StringComparison.OrdinalIgnoreCase))).Select(i => i.Split(ArgumentNameSeparators, 2).LastOrDefault()).Where(y => !String.IsNullOrWhiteSpace(y))) | ||
{ | ||
foreach (string item in arg.Split(ArgumentValueSeparators, StringSplitOptions.RemoveEmptyEntries).Select(i => i.Trim()).Where(i => !String.IsNullOrWhiteSpace(i))) | ||
{ | ||
yield return item; | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System.Text.RegularExpressions; | ||
using NuGet.Packaging.Core; | ||
|
||
namespace ConsoleApp | ||
{ | ||
internal class ImportRegularExpressions : RegularExpressionsForPackagesBase | ||
{ | ||
protected override Regex GetRegularExpression(PackageIdentity packageIdentity) | ||
{ | ||
return new Regex($@".*{Regex.Escape(packageIdentity.Id)}\.{Regex.Escape(packageIdentity.Version.ToString())}.+{Regex.Escape(packageIdentity.Id)}\.(props|targets)", RegexOptions.IgnoreCase); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using System.Reflection; | ||
|
||
namespace ConsoleApp | ||
{ | ||
internal class Program | ||
{ | ||
// @"D:\Truman2\private\Libraries\ServiceClient\public\sample" | ||
private static int Main(string[] args) | ||
{ | ||
try | ||
{ | ||
if (args.Any(i => i.Equals("/debug", StringComparison.OrdinalIgnoreCase))) | ||
{ | ||
Debugger.Break(); | ||
} | ||
|
||
if (args.Any(i => i.Equals("/?", StringComparison.OrdinalIgnoreCase))) | ||
{ | ||
return PrintUsage(); | ||
} | ||
|
||
bool quiet = args.Any(i => i.StartsWith("/q", StringComparison.OrdinalIgnoreCase)); | ||
|
||
string repositoryPath = args.SingleOrDefault(i => i[0] != '/'); | ||
|
||
if (String.IsNullOrWhiteSpace(repositoryPath)) | ||
{ | ||
return PrintUsage("You must specify a repository path"); | ||
} | ||
|
||
List<string> exclusions = args.GetCommandLineArgumentValues("/e", "exclude").ToList(); | ||
|
||
Console.WriteLine($" EnlistmentRoot: '{repositoryPath}'"); | ||
Console.WriteLine($" Exclusion: '{String.Join($"{Environment.NewLine} Exclusion: '", exclusions)}'"); | ||
Console.WriteLine(); | ||
|
||
if (!quiet) | ||
{ | ||
Console.Write("Ensure there are no files checked out in git before continuing! Continue? (Y/N) "); | ||
if (!Console.ReadLine().StartsWith("Y", StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
return 0; | ||
} | ||
} | ||
|
||
using (ProjectConverter projectConverter = new ProjectConverter()) | ||
{ | ||
Console.WriteLine("Converting..."); | ||
|
||
projectConverter.ConvertRepository(repositoryPath, exclusions); | ||
|
||
Console.WriteLine("Success!"); | ||
} | ||
} | ||
catch (Exception e) | ||
{ | ||
Console.Error.WriteLine(e.ToString()); | ||
|
||
return 1; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
private static int PrintUsage(string errorMessage = null) | ||
{ | ||
if (!String.IsNullOrWhiteSpace(errorMessage)) | ||
{ | ||
Console.Error.WriteLine(errorMessage); | ||
} | ||
|
||
Console.WriteLine("Converts a repository from packages.config to PackageReference."); | ||
Console.WriteLine(); | ||
|
||
Console.WriteLine($"{Assembly.GetExecutingAssembly().GetName().Name}.exe repositoryPath [/quiet] [/exclude:path1;path2]"); | ||
Console.WriteLine(); | ||
Console.WriteLine(" Repository Full path to the repository root to convert"); | ||
Console.WriteLine(); | ||
Console.WriteLine(" /quiet Do not prompt before converting the tree"); | ||
Console.WriteLine(); | ||
Console.WriteLine(" /exclude One or more full paths to any directories to exclude"); | ||
Console.WriteLine(); | ||
Console.WriteLine(" Example:"); | ||
Console.WriteLine(); | ||
Console.WriteLine(" /exclude:\"D:\\RepoA\\src\\ProjectX\""); | ||
|
||
Console.WriteLine(); | ||
Console.WriteLine(" /debug Launch the debugger before executing"); | ||
|
||
return String.IsNullOrWhiteSpace(errorMessage) ? 0 : 1; | ||
} | ||
} | ||
} |
Oops, something went wrong.