我希望找到一种类似于在旧版本的 VS 中调试 Asp.Net/SOAP 的方法,其中 MSTest 引擎将启动 IISExpress 并将 VS 附加到 Asp.Net 项目。支持编辑并继续。
到目前为止,我已经制定了以下方法:
RestSharp 代码:
var url = $"http://localhost:7071/api";
var functionKey = "this value is ignored by 'Azure Functions Core Tools' ";
var client = new RestSharp.RestClient(url);
var request = new RestSharp.RestRequest("GetConnectionString", RestSharp.Method.POST);
request.AddHeader("x-functions-key", functionKey);
var response = client.Execute<string>(request);
运行 VS 的第二个实例并运行函数。
更新代码以反映 Azure Functions 核心工具显示的 url 路径。
编辑并继续工作。
将此类添加到 UnitTest 项目中:
附加到 func.exe 进程以调试函数
编辑并继续不起作用。
[TestClass]
public class Initializer
{
static System.Diagnostics.Process process { get; set; }
[AssemblyInitialize]
public static void Initialize(TestContext context)
{
//process does not use the WorkingDirectory properly with %userprofile%
var userprofile = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
var path = $@"{userprofile}\source\repos\mypro\...\myproj.Functions\bin\Debug\netcoreapp3.1";
var startInfo = new ProcessStartInfo
{
FileName = @"cmd.exe",
Arguments = @"/C ""%localappdata%\AzureFunctionsTools\Releases\3.2.0\cli_x64\func.exe host start --port 7071 --pause-on-error""",
//RedirectStandardInput = true,
//RedirectStandardOutput = true,
//RedirectStandardError = true,
//UseShellExecute = false,
UseShellExecute = true,
WorkingDirectory = path
};
process = new System.Diagnostics.Process()
{
StartInfo = startInfo
};
process.Start();
// Thread.Sleep(3000);
}
[AssemblyCleanup]
public static void Cleanup()
{
process.CloseMainWindow();
}
}
启动func.exe进程
工作文件夹:...\source\repos\xxx\xxx\xxx.Functions\bin\Debug\netcoreapp3.1\
命令行:
"C:\Users\username\AppData\Local\AzureFunctionsTools\Releases\3.2.0\cli_x64\func.exe" host start --port 7071 --pause-on-error
附加到 func.exe 进程。
编辑并继续不起作用。