C# 获取解决方案中的所有应用程序和web配置文件

C# 获取解决方案中的所有应用程序和web配置文件,c#,.net,C#,.net,我想写一个测试来检查我的应用程序配置文件中的一些设置是否存在 我该如何获取解决方案中的所有app/web配置文件?据我所知,您的帖子, 请使用以下命令获取目录中的所有文件 public string[] GetAllFilesInDirectory(string path, string startsWith, string fileExt) { string[] filenames = Directory.GetFiles(path, startsWith + "*"

我想写一个测试来检查我的应用程序配置文件中的一些设置是否存在


我该如何获取解决方案中的所有app/web配置文件?

据我所知,您的帖子, 请使用以下命令获取
目录中的
所有文件

public string[] GetAllFilesInDirectory(string path, string startsWith, string fileExt)
    {
        string[] filenames = Directory.GetFiles(path, startsWith + "*" + fileExt);
        return filenames;

    }
用法:

 string[] arr= GetAllFilesInDirectory(somepath,startswith,".config");

希望这有帮助

使用目录搜索可以获取文件

  string[] configFiles = Directory.GetFiles( @"YourSolutonDirectoryLocation", "*.config", SearchOption.AllDirectories)
                               .Where(x => x.EndsWith("App.config") || x.EndsWith("Web.config")).ToArray();

你的意思是“如何访问特定目录的文件?”我想写一个测试,确保我的解决方案中的所有应用程序配置文件都不包含特定的设置。如果我向解决方案中添加了另一个项目,但该项目不包含该配置,则此操作将失败