Browse Source

use relative path if reference and target project are in the same root path

pull/2186/head
文煌 5 years ago committed by Siegfried Pammer
parent
commit
a5fdb05c6f
  1. 5
      ICSharpCode.Decompiler/CSharp/ProjectDecompiler/IProjectInfoProvider.cs
  2. 3
      ICSharpCode.Decompiler/CSharp/ProjectDecompiler/ProjectFileWriterSdkStyle.cs
  3. 36
      ICSharpCode.Decompiler/CSharp/ProjectDecompiler/WholeProjectDecompiler.cs

5
ICSharpCode.Decompiler/CSharp/ProjectDecompiler/IProjectInfoProvider.cs

@ -42,6 +42,11 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler @@ -42,6 +42,11 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler
/// </summary>
Guid ProjectGuid { get; }
/// <summary>
/// Gets the target directory of the project
/// </summary>
string TargetDirectory { get; }
/// <summary>
/// Gets the name of the key file being used for strong name signing. Can be null if no file is available.
/// </summary>

3
ICSharpCode.Decompiler/CSharp/ProjectDecompiler/ProjectFileWriterSdkStyle.cs

@ -24,6 +24,7 @@ using System.Reflection.PortableExecutable; @@ -24,6 +24,7 @@ using System.Reflection.PortableExecutable;
using System.Xml;
using ICSharpCode.Decompiler.Metadata;
using ICSharpCode.Decompiler.Util;
namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler
{
@ -186,7 +187,7 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler @@ -186,7 +187,7 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler
var asembly = project.AssemblyResolver.Resolve(reference);
if (asembly != null && !project.AssemblyResolver.IsGacAssembly(reference))
{
xml.WriteElementString("HintPath", asembly.FileName);
xml.WriteElementString("HintPath", FileUtility.GetRelativePath(project.TargetDirectory, asembly.FileName));
}
xml.WriteEndElement();

36
ICSharpCode.Decompiler/CSharp/ProjectDecompiler/WholeProjectDecompiler.cs

@ -72,6 +72,15 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler @@ -72,6 +72,15 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler
/// </summary>
public Guid ProjectGuid { get; }
/// <summary>
/// The target directory that the decompiled files are written to.
/// </summary>
/// <remarks>
/// This property is set by DecompileProject() and protected so that overridden protected members
/// can access it.
/// </remarks>
public string TargetDirectory { get; protected set; }
/// <summary>
/// Path to the snk file to use for signing.
/// <c>null</c> to not sign.
@ -112,15 +121,6 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler @@ -112,15 +121,6 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler
// per-run members
HashSet<string> directories = new HashSet<string>(Platform.FileNameComparer);
/// <summary>
/// The target directory that the decompiled files are written to.
/// </summary>
/// <remarks>
/// This field is set by DecompileProject() and protected so that overridden protected members
/// can access it.
/// </remarks>
protected string targetDirectory;
readonly IProjectFileWriter projectWriter;
public void DecompileProject(PEFile moduleDefinition, string targetDirectory, CancellationToken cancellationToken = default(CancellationToken))
@ -138,7 +138,7 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler @@ -138,7 +138,7 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler
{
throw new InvalidOperationException("Must set TargetDirectory");
}
this.targetDirectory = targetDirectory;
TargetDirectory = targetDirectory;
directories.Clear();
var files = WriteCodeFilesInProject(moduleDefinition, cancellationToken).ToList();
files.AddRange(WriteResourceFilesInProject(moduleDefinition));
@ -183,9 +183,9 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler @@ -183,9 +183,9 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler
const string prop = "Properties";
if (directories.Add(prop))
Directory.CreateDirectory(Path.Combine(targetDirectory, prop));
Directory.CreateDirectory(Path.Combine(TargetDirectory, prop));
string assemblyInfo = Path.Combine(prop, "AssemblyInfo.cs");
using (StreamWriter w = new StreamWriter(Path.Combine(targetDirectory, assemblyInfo)))
using (StreamWriter w = new StreamWriter(Path.Combine(TargetDirectory, assemblyInfo)))
{
syntaxTree.AcceptVisitor(new CSharpOutputVisitor(w, Settings.CSharpFormattingOptions));
}
@ -207,7 +207,7 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler @@ -207,7 +207,7 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler
{
string dir = CleanUpFileName(metadata.GetString(type.Namespace));
if (directories.Add(dir))
Directory.CreateDirectory(Path.Combine(targetDirectory, dir));
Directory.CreateDirectory(Path.Combine(TargetDirectory, dir));
return Path.Combine(dir, file);
}
}, StringComparer.OrdinalIgnoreCase).ToList();
@ -221,7 +221,7 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler @@ -221,7 +221,7 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler
CancellationToken = cancellationToken
},
delegate (IGrouping<string, TypeDefinitionHandle> file) {
using (StreamWriter w = new StreamWriter(Path.Combine(targetDirectory, file.Key)))
using (StreamWriter w = new StreamWriter(Path.Combine(TargetDirectory, file.Key)))
{
try
{
@ -264,7 +264,7 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler @@ -264,7 +264,7 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler
string dirName = Path.GetDirectoryName(fileName);
if (!string.IsNullOrEmpty(dirName) && directories.Add(dirName))
{
Directory.CreateDirectory(Path.Combine(targetDirectory, dirName));
Directory.CreateDirectory(Path.Combine(TargetDirectory, dirName));
}
Stream entryStream = (Stream)value;
entryStream.Position = 0;
@ -306,7 +306,7 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler @@ -306,7 +306,7 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler
else
{
string fileName = GetFileNameForResource(r.Name);
using (FileStream fs = new FileStream(Path.Combine(targetDirectory, fileName), FileMode.Create, FileAccess.Write))
using (FileStream fs = new FileStream(Path.Combine(TargetDirectory, fileName), FileMode.Create, FileAccess.Write))
{
stream.Position = 0;
stream.CopyTo(fs);
@ -323,7 +323,7 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler @@ -323,7 +323,7 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler
string resx = Path.ChangeExtension(fileName, ".resx");
try
{
using (FileStream fs = new FileStream(Path.Combine(targetDirectory, resx), FileMode.Create, FileAccess.Write))
using (FileStream fs = new FileStream(Path.Combine(TargetDirectory, resx), FileMode.Create, FileAccess.Write))
using (ResXResourceWriter writer = new ResXResourceWriter(fs))
{
foreach (var entry in new ResourcesFile(entryStream))
@ -342,7 +342,7 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler @@ -342,7 +342,7 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler
// if the .resources can't be decoded, just save them as-is
}
}
using (FileStream fs = new FileStream(Path.Combine(targetDirectory, fileName), FileMode.Create, FileAccess.Write))
using (FileStream fs = new FileStream(Path.Combine(TargetDirectory, fileName), FileMode.Create, FileAccess.Write))
{
entryStream.CopyTo(fs);
}

Loading…
Cancel
Save