diff --git a/ICSharpCode.Decompiler/CSharp/ProjectDecompiler/IProjectInfoProvider.cs b/ICSharpCode.Decompiler/CSharp/ProjectDecompiler/IProjectInfoProvider.cs
index c9d2513de..307ca5060 100644
--- a/ICSharpCode.Decompiler/CSharp/ProjectDecompiler/IProjectInfoProvider.cs
+++ b/ICSharpCode.Decompiler/CSharp/ProjectDecompiler/IProjectInfoProvider.cs
@@ -42,6 +42,11 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler
///
Guid ProjectGuid { get; }
+ ///
+ /// Gets the target directory of the project
+ ///
+ string TargetDirectory { get; }
+
///
/// Gets the name of the key file being used for strong name signing. Can be null if no file is available.
///
diff --git a/ICSharpCode.Decompiler/CSharp/ProjectDecompiler/ProjectFileWriterSdkStyle.cs b/ICSharpCode.Decompiler/CSharp/ProjectDecompiler/ProjectFileWriterSdkStyle.cs
index 2e8e72573..ba05523cd 100644
--- a/ICSharpCode.Decompiler/CSharp/ProjectDecompiler/ProjectFileWriterSdkStyle.cs
+++ b/ICSharpCode.Decompiler/CSharp/ProjectDecompiler/ProjectFileWriterSdkStyle.cs
@@ -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
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();
diff --git a/ICSharpCode.Decompiler/CSharp/ProjectDecompiler/WholeProjectDecompiler.cs b/ICSharpCode.Decompiler/CSharp/ProjectDecompiler/WholeProjectDecompiler.cs
index a817ddc3e..2c3270c2a 100644
--- a/ICSharpCode.Decompiler/CSharp/ProjectDecompiler/WholeProjectDecompiler.cs
+++ b/ICSharpCode.Decompiler/CSharp/ProjectDecompiler/WholeProjectDecompiler.cs
@@ -72,6 +72,15 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler
///
public Guid ProjectGuid { get; }
+ ///
+ /// The target directory that the decompiled files are written to.
+ ///
+ ///
+ /// This property is set by DecompileProject() and protected so that overridden protected members
+ /// can access it.
+ ///
+ public string TargetDirectory { get; protected set; }
+
///
/// Path to the snk file to use for signing.
/// null to not sign.
@@ -112,15 +121,6 @@ namespace ICSharpCode.Decompiler.CSharp.ProjectDecompiler
// per-run members
HashSet directories = new HashSet(Platform.FileNameComparer);
- ///
- /// The target directory that the decompiled files are written to.
- ///
- ///
- /// This field is set by DecompileProject() and protected so that overridden protected members
- /// can access it.
- ///
- 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
{
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
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
{
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
CancellationToken = cancellationToken
},
delegate (IGrouping 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
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
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
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
// 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);
}