How to pass Dynamic value to pathtowebapp [AspNetDevelopmentServer(identifier,pathtowebapp)] attribute in Unit Test method

100 views Asked by At

I Have unit test project in this I am using AspNetDevelopmentServer attribute to test my wcf Service locally. It working fine When I give the arguments hardcoded like this

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

When I try to pass this arguments through variable (dynamically) like

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

It throws error like this:

"An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type "

Is any other way to pass a dynamic value to attribute? Thanks is advance.

1

There are 1 answers

0
Marc Fearby On

Try using relative paths to the other project (presumably in the same Visual Studio solution within C:\Users\LocalSourcePath):

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

Paths are relative your MyProjectTests\bin\debug folder