Added output path switch to ProjectConverter: we are now able to select where to create the converted project
This commit is contained in:
parent
d0f477790b
commit
bf101259fe
@ -31,9 +31,9 @@ namespace ProjectConverter
|
|||||||
public abstract string Name { get; }
|
public abstract string Name { get; }
|
||||||
|
|
||||||
#region ConvertAllProjects
|
#region ConvertAllProjects
|
||||||
public void ConvertAllProjects(string solutionFilepath)
|
public void ConvertAllProjects(string solutionFilepath, string destinationPath)
|
||||||
{
|
{
|
||||||
ProjectPath[] allProjects = CollectAllProjects(solutionFilepath);
|
ProjectPath[] allProjects = CollectAllProjects(solutionFilepath, destinationPath);
|
||||||
|
|
||||||
for (int index = 0; index < allProjects.Length; index++)
|
for (int index = 0; index < allProjects.Length; index++)
|
||||||
{
|
{
|
||||||
@ -45,9 +45,9 @@ namespace ProjectConverter
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region ConvertProject
|
#region ConvertProject
|
||||||
public void ConvertProject(string projectFilePath)
|
public void ConvertProject(string projectFilePath, string destinationPath)
|
||||||
{
|
{
|
||||||
ProjectPath projectPath = new ProjectPath(this, projectFilePath, ".");
|
ProjectPath projectPath = new ProjectPath(this, projectFilePath, ".", destinationPath);
|
||||||
ConvertProject(projectPath);
|
ConvertProject(projectPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -220,7 +220,11 @@ namespace ProjectConverter
|
|||||||
string referencePath = includeAttribute.Value;
|
string referencePath = includeAttribute.Value;
|
||||||
if (referencePath.EndsWith(".csproj"))
|
if (referencePath.EndsWith(".csproj"))
|
||||||
{
|
{
|
||||||
referencePath = referencePath.Replace(".csproj", "_" + Postfix + ".csproj");
|
if (!string.IsNullOrEmpty(Postfix))
|
||||||
|
{
|
||||||
|
referencePath = referencePath.Replace(".csproj", "_" + Postfix + ".csproj");
|
||||||
|
}
|
||||||
|
|
||||||
string basePath = Path.GetDirectoryName(CurrentProject.FullSourcePath);
|
string basePath = Path.GetDirectoryName(CurrentProject.FullSourcePath);
|
||||||
string fullReferencePath = Path.Combine(basePath, referencePath);
|
string fullReferencePath = Path.Combine(basePath, referencePath);
|
||||||
if (File.Exists(fullReferencePath))
|
if (File.Exists(fullReferencePath))
|
||||||
@ -233,7 +237,7 @@ namespace ProjectConverter
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region CollectAllProjects
|
#region CollectAllProjects
|
||||||
private ProjectPath[] CollectAllProjects(string solutionFilepath)
|
private ProjectPath[] CollectAllProjects(string solutionFilepath, string destinationPath)
|
||||||
{
|
{
|
||||||
var solution = VsSolution.Load(solutionFilepath);
|
var solution = VsSolution.Load(solutionFilepath);
|
||||||
var result = new List<ProjectPath>();
|
var result = new List<ProjectPath>();
|
||||||
@ -242,7 +246,7 @@ namespace ProjectConverter
|
|||||||
|
|
||||||
foreach (var project in solution.Projects)
|
foreach (var project in solution.Projects)
|
||||||
if (project.IsCsProject && project.RelativePath.Contains("Tools") == false)
|
if (project.IsCsProject && project.RelativePath.Contains("Tools") == false)
|
||||||
result.Add(new ProjectPath(this, project.RelativePath, basePath));
|
result.Add(new ProjectPath(this, project.RelativePath, basePath, destinationPath));
|
||||||
|
|
||||||
return result.ToArray();
|
return result.ToArray();
|
||||||
}
|
}
|
||||||
@ -282,7 +286,7 @@ namespace ProjectConverter
|
|||||||
{
|
{
|
||||||
const string filepath = @"D:\code\csharp\ANX.Framework\ANX.Framework.sln";
|
const string filepath = @"D:\code\csharp\ANX.Framework\ANX.Framework.sln";
|
||||||
var converter = new MetroConverter();
|
var converter = new MetroConverter();
|
||||||
ProjectPath[] result = converter.CollectAllProjects(filepath);
|
ProjectPath[] result = converter.CollectAllProjects(filepath, string.Empty);
|
||||||
|
|
||||||
Assert.Greater(result.Length, 0);
|
Assert.Greater(result.Length, 0);
|
||||||
}
|
}
|
||||||
@ -294,7 +298,7 @@ namespace ProjectConverter
|
|||||||
{
|
{
|
||||||
const string filepath = @"D:\code\csharp\ANX.Framework\ANX.Framework.sln";
|
const string filepath = @"D:\code\csharp\ANX.Framework\ANX.Framework.sln";
|
||||||
var converter = new MetroConverter();
|
var converter = new MetroConverter();
|
||||||
converter.ConvertAllProjects(filepath);
|
converter.ConvertAllProjects(filepath, string.Empty);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -304,7 +308,7 @@ namespace ProjectConverter
|
|||||||
{
|
{
|
||||||
const string filepath = @"D:\code\csharp\ANX.Framework\ANX.Framework.sln";
|
const string filepath = @"D:\code\csharp\ANX.Framework\ANX.Framework.sln";
|
||||||
var converter = new PsVitaConverter();
|
var converter = new PsVitaConverter();
|
||||||
converter.ConvertAllProjects(filepath);
|
converter.ConvertAllProjects(filepath, string.Empty);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -314,7 +318,7 @@ namespace ProjectConverter
|
|||||||
{
|
{
|
||||||
const string filepath = @"D:\code\csharp\ANX.Framework\ANX.Framework.sln";
|
const string filepath = @"D:\code\csharp\ANX.Framework\ANX.Framework.sln";
|
||||||
var converter = new LinuxConverter();
|
var converter = new LinuxConverter();
|
||||||
converter.ConvertAllProjects(filepath);
|
converter.ConvertAllProjects(filepath, string.Empty);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,10 @@ namespace ProjectConverter
|
|||||||
new XnaConverter(),
|
new XnaConverter(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private static readonly List<string> switches = new List<string>();
|
||||||
|
private static readonly Dictionary<string, string> keyValueParameters = new Dictionary<string, string>();
|
||||||
|
private static readonly List<string> files = new List<string>();
|
||||||
|
|
||||||
[STAThread]
|
[STAThread]
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
@ -30,29 +34,27 @@ namespace ProjectConverter
|
|||||||
// To restore "old" behaviour use:
|
// To restore "old" behaviour use:
|
||||||
// ProjectConverter /linux /psvita /windowsmetro ../../ANX.Framework.sln
|
// ProjectConverter /linux /psvita /windowsmetro ../../ANX.Framework.sln
|
||||||
//
|
//
|
||||||
// For testing only
|
|
||||||
//args = new[] { "/linux", "/psvita", "/windowsmetro", "../../ANX.Framework.sln" };
|
|
||||||
|
|
||||||
Directory.SetCurrentDirectory(Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location));
|
Directory.SetCurrentDirectory(Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location));
|
||||||
|
|
||||||
var switches = new List<string>();
|
|
||||||
var keyValueParameters = new Dictionary<string,string>();
|
|
||||||
var files = new List<string>();
|
|
||||||
|
|
||||||
foreach (string arg in args)
|
foreach (string arg in args)
|
||||||
{
|
{
|
||||||
if (arg.StartsWith("/") || arg.StartsWith("-"))
|
if (arg.StartsWith("/") || arg.StartsWith("-"))
|
||||||
{
|
{
|
||||||
if (arg.Contains("="))
|
if (arg.Contains("="))
|
||||||
{
|
{
|
||||||
string[] parts = arg.Split('=');
|
string[] parts = arg.Split('=');
|
||||||
keyValueParameters[parts[0].Trim().ToLowerInvariant()] = parts[1].Trim().ToLowerInvariant();
|
keyValueParameters[parts[0].Trim().ToLowerInvariant()] = parts[1].Trim().ToLowerInvariant();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
switches.Add(arg.Substring(1).Trim().ToLowerInvariant());
|
{
|
||||||
|
switches.Add(arg.Substring(1).Trim().ToLowerInvariant());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (File.Exists(arg))
|
else if (File.Exists(arg))
|
||||||
files.Add(arg);
|
{
|
||||||
|
files.Add(arg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (string file in files)
|
foreach (string file in files)
|
||||||
@ -65,10 +67,10 @@ namespace ProjectConverter
|
|||||||
switch (fileExt)
|
switch (fileExt)
|
||||||
{
|
{
|
||||||
case ".sln":
|
case ".sln":
|
||||||
converter.ConvertAllProjects(file);
|
converter.ConvertAllProjects(file, TryGetDestinationPath());
|
||||||
break;
|
break;
|
||||||
case ".csproj":
|
case ".csproj":
|
||||||
converter.ConvertProject(file);
|
converter.ConvertProject(file, TryGetDestinationPath());
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new NotImplementedException("unsupported file type '" + fileExt + "'");
|
throw new NotImplementedException("unsupported file type '" + fileExt + "'");
|
||||||
@ -77,5 +79,18 @@ namespace ProjectConverter
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static string TryGetDestinationPath()
|
||||||
|
{
|
||||||
|
foreach (KeyValuePair<string, string> kvp in keyValueParameters)
|
||||||
|
{
|
||||||
|
if (string.Equals(kvp.Key, "/O", StringComparison.InvariantCultureIgnoreCase))
|
||||||
|
{
|
||||||
|
return kvp.Value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -58,21 +58,36 @@ namespace ProjectConverter
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProjectPath(Converter converter, string relativeSourcePath, string basePath)
|
public ProjectPath(Converter converter, string relativeSourcePath, string basePath, string destinationPath)
|
||||||
{
|
{
|
||||||
RelativeSourcePath = relativeSourcePath;
|
RelativeSourcePath = relativeSourcePath;
|
||||||
FullSourcePath = Path.Combine(basePath, relativeSourcePath);
|
FullSourcePath = Path.Combine(basePath, relativeSourcePath);
|
||||||
|
|
||||||
RelativeDestinationPath = BuildTargetFilepath(converter);
|
if (string.IsNullOrEmpty(destinationPath))
|
||||||
|
{
|
||||||
|
RelativeDestinationPath = BuildTargetFilepath(converter);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!Directory.Exists(destinationPath))
|
||||||
|
{
|
||||||
|
Directory.CreateDirectory(destinationPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
RelativeDestinationPath = Path.Combine(destinationPath, Path.GetFileName(relativeSourcePath));
|
||||||
|
}
|
||||||
|
|
||||||
FullDestinationPath = Path.Combine(basePath, RelativeDestinationPath);
|
FullDestinationPath = Path.Combine(basePath, RelativeDestinationPath);
|
||||||
|
|
||||||
try
|
//TODO: never ever ignore all exceptions without proper handling
|
||||||
{
|
|
||||||
|
//try
|
||||||
|
//{
|
||||||
LoadProjectFile();
|
LoadProjectFile();
|
||||||
}
|
//}
|
||||||
catch
|
//catch
|
||||||
{
|
//{
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Save
|
#region Save
|
||||||
@ -92,7 +107,10 @@ namespace ProjectConverter
|
|||||||
filename = filename.Substring(0, filename.IndexOf('_'));
|
filename = filename.Substring(0, filename.IndexOf('_'));
|
||||||
}
|
}
|
||||||
|
|
||||||
filename += "_" + converter.Postfix;
|
if (!string.IsNullOrEmpty(converter.Postfix))
|
||||||
|
{
|
||||||
|
filename += "_" + converter.Postfix;
|
||||||
|
}
|
||||||
|
|
||||||
return Path.Combine(basePath, filename + ".csproj");
|
return Path.Combine(basePath, filename + ".csproj");
|
||||||
}
|
}
|
||||||
@ -121,18 +139,18 @@ namespace ProjectConverter
|
|||||||
string testRelativeSourcePath = "ANX.Framework.csproj";
|
string testRelativeSourcePath = "ANX.Framework.csproj";
|
||||||
|
|
||||||
var projPath = new ProjectPath(new PsVitaConverter(),
|
var projPath = new ProjectPath(new PsVitaConverter(),
|
||||||
testRelativeSourcePath, testBasePath);
|
testRelativeSourcePath, testBasePath, string.Empty);
|
||||||
Assert.AreEqual(projPath.RelativeDestinationPath,
|
Assert.AreEqual(projPath.RelativeDestinationPath,
|
||||||
"ANX.Framework_PSVita.csproj");
|
"ANX.Framework_PSVita.csproj");
|
||||||
|
|
||||||
projPath = new ProjectPath(new LinuxConverter(),
|
projPath = new ProjectPath(new LinuxConverter(),
|
||||||
"ANX.Framework_IOS.csproj", testBasePath);
|
"ANX.Framework_IOS.csproj", testBasePath, string.Empty);
|
||||||
|
|
||||||
Assert.AreEqual(projPath.RelativeDestinationPath,
|
Assert.AreEqual(projPath.RelativeDestinationPath,
|
||||||
"ANX.Framework_Linux.csproj");
|
"ANX.Framework_Linux.csproj");
|
||||||
|
|
||||||
projPath = new ProjectPath(new MetroConverter(),
|
projPath = new ProjectPath(new MetroConverter(),
|
||||||
"ANX.Framework_IOS_Android_WindowsXNA.csproj", testBasePath);
|
"ANX.Framework_IOS_Android_WindowsXNA.csproj", testBasePath, string.Empty);
|
||||||
Assert.AreEqual(projPath.RelativeDestinationPath,
|
Assert.AreEqual(projPath.RelativeDestinationPath,
|
||||||
"ANX.Framework_WindowsMetro.csproj");
|
"ANX.Framework_WindowsMetro.csproj");
|
||||||
}
|
}
|
||||||
|
@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
|
|||||||
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
|
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
|
||||||
// übernehmen, indem Sie "*" eingeben:
|
// übernehmen, indem Sie "*" eingeben:
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
[assembly: AssemblyVersion("1.2.2.*")]
|
[assembly: AssemblyVersion("1.2.3.*")]
|
||||||
[assembly: AssemblyFileVersion("1.2.2.0")]
|
[assembly: AssemblyFileVersion("1.2.3.0")]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user