如何检查NuGet包中是否存在Pack / component Uri?

时间:2019-02-24 15:30:48

标签: c# .net uri nuget-package file-exists

如何检查引用的项目中是否存在Uri(文件)?

this answer我都试图捕获一个FileNotFound异常,但它根本没有引发任何异常

string x;

try {
    var Uri = new Uri("/FamFamFam.Flags.Wpf;component/Images/some_wrong_file.png",
        UriKind.Relative);
    x = "a";
}

catch(Exception) {
    x = "b";
}

MessageBox.Show(x);

对于每个an MSDN thread,我尝试检查结果Bitmap是否为空,但始终显示'a':

string x;

try {
    var Bitmap = new BitmapImage(new Uri(
        "/FamFamFam.Flags.Wpf;component/Images/some_wrong_file.png", UriKind.Relative));
    Flag_Image.Source = Bitmap ?? throw new Exception();
    x = "a";
}

catch(Exception) {
    Flag_Image.Source = new BitmapImage(new Uri(
        "/FamFamFam.Flags.Wpf;component/Images/ca.png", UriKind.Relative));
    x = "b";
}

MessageBox.Show(x);

0 个答案:

没有答案