Skip to content

Commit 6c7466b

Browse files
committed
尝试获取输出文件夹
1 parent b22149b commit 6c7466b

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

Code/UsingMSBuildCopyOutputFileToFastDebug/LaunchSettingsParser.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public bool Execute()
2222
if (!File.Exists(file))
2323
{
2424
Console.WriteLine($"找不到{file}文件,读取结束");
25-
return true;
25+
return false;
2626
}
2727

2828
var text = File.ReadAllText(file);
@@ -52,7 +52,7 @@ public bool Execute()
5252
}
5353
}
5454

55-
return true;
55+
return false;
5656
}
5757

5858
public string LaunchMainProjectPath { set; get; }

Code/UsingMSBuildCopyOutputFileToFastDebug/Program.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,28 @@ private static DirectoryInfo GetTargetFolder(CopyOutputFileOptions copyOutputFil
6666
// 如果用户有设置此文件夹,那就期望是输出到此文件夹
6767
if (!string.IsNullOrEmpty(mainProjectPath))
6868
{
69+
if (Directory.Exists(mainProjectPath) is false)
70+
{
71+
throw new DirectoryNotFoundException(
72+
$"Can not find '{mainProjectPath}' FullPath={Path.GetFullPath(mainProjectPath)}");
73+
}
74+
6975
return new DirectoryInfo(mainProjectPath);
7076
}
77+
// 尝试去读取 LaunchSettings 文件
78+
var launchSettingsParser = new LaunchSettingsParser();
79+
if (launchSettingsParser.Execute())
80+
{
81+
var launchMainProjectPath = launchSettingsParser.LaunchMainProjectPath;
82+
if (Directory.Exists(launchMainProjectPath) is false)
83+
{
84+
throw new DirectoryNotFoundException($"Can not find '{launchMainProjectPath}'");
85+
}
86+
87+
return new DirectoryInfo(launchMainProjectPath);
88+
}
7189

72-
return null;
90+
throw new ArgumentException($"没有从 MainProjectPath 和 LaunchSettings 获取到输出的文件夹");
7391
}
7492

7593
private static IMSBuildLogger Logger { get; } = new MSBuildConsoleLogger();

0 commit comments

Comments
 (0)