0

我有单元测试项目,我正在使用 AspNetDevelopmentServer 属性在本地测试我的 wcf 服务。当我像这样硬编码参数时,它工作正常

[AspNetDevelopmentServer("Test",@"C:\\Users\\LocalSourcePath")]

当我尝试通过变量(动态)传递这个参数时

string path = @Directory.GetParent((Directory.GetParent(Path.GetDirectoryName((new Uri(System.Reflection.Assembly.GetExecutingAssembly().CodeBase)).LocalPath))).Parent.FullName).FullName+"\\Publish";
[AspNetDevelopmentServer("Test",path )]

它抛出这样的错误:

“属性参数必须是属性参数类型的常量表达式、typeof表达式或数组创建表达式”

有没有其他方法可以将动态值传递给属性?谢谢是提前。

4

1 回答 1

0

尝试使用其他项目的相对路径(可能在 C:\Users\LocalSourcePath 中的同一 Visual Studio 解决方案中):

[AspNetDevelopmentServer("Test", @"..\..\MyProject")]

路径是相对于您的 MyProjectTests\bin\debug 文件夹

于 2018-08-16T01:17:17.427 回答