我正在编辑我的问题,以便更容易理解。
以下是一个示例解决方案:https://github.com/mckenn55/PowershellTest
我创建了一个全新的net47 MVC项目。我添加了一个名为" Database"并且该区域内的控制器称为"更新"。在该控制器中,我有以下内容:
public ActionResult Index()
{
return View(Execute());
}
public static List<string> Execute()
{
var returnable = new List<string>();
var assembly = Assembly.GetExecutingAssembly();
string codeBase = assembly.CodeBase;
UriBuilder uri = new UriBuilder(codeBase);
string path = Uri.UnescapeDataString(uri.Path);
var assemblyLocation = Path.GetDirectoryName(path);
string resourcePath = "";
string ModuleName = assembly.ManifestModule.Name;
ModuleName = ModuleName.Substring(0, ModuleName.LastIndexOf("."));
ModuleName = ModuleName.Replace(' ', '_').Replace(".", "");
string FolderPath = "Areas.Database.SQL";
FolderPath = FolderPath.Replace(' ', '_');
if (FolderPath != null && FolderPath.Length > 0 && FolderPath[FolderPath.Length - 1] == '.')
FolderPath = FolderPath.Substring(0, FolderPath.Length - 1);
StringBuilder filepath = new StringBuilder();
filepath.Append(ModuleName);
if (FolderPath != null && FolderPath.Length > 0)
{
filepath.Append('.' + FolderPath);
filepath.Append('.');
}
resourcePath = filepath.ToString();
string[] resourceNames = assembly.GetManifestResourceNames();
foreach (var resourceName in resourceNames)
{
if (Regex.Match(resourceName, "^" + resourcePath).Success)
{
returnable.Add(resourceName);
}
}
var orderedFileNames = new List<string>();
if (returnable != null && returnable.Any())
{
orderedFileNames = returnable.OrderBy(q => q).ToList();
}
else
{
returnable.Add("No files found");
}
return returnable;
}
在数据库区域内,我有一个名为&#34; SQL&#34;的目录。在该目录中,我有一个文件TestFile.sql,作为嵌入式资源包含在解决方案中。使用索引操作查看时,Execute()方法的结果是&#34; PSTest.Areas.Database.SQL.TestFile.sql&#34;。我想在Powershell中看到同样的事情。我尝试过以下方法:
> Add-Type -path "C:\Temp\PSTest\PSTest\bin\PSTest.dll"
> [PSTest.Areas.Database.UpdateController]::Execute()
No Files Found
我的目标是否可以通过powershell进行,如果可以,怎么做?
答案 0 :(得分:0)
我无法单独使用PowerShell找到解决方案。我编写了一个C#控制台应用程序,可以毫无问题地执行这些操作。