Reputation: 4080
I have a web service class that the rest of the framework depends on to grab its data, but the web service class needs to have different method attributes depending on what environment it's in. For instance...
[SoapDocumentMethodAttribute("https://example",...)]
public string Test()
{
//doSomething
}
See that "https://example"? That needs to change depending on the environment. AFAIK you can't make that string dynamic for runtime, it has to be compiled that way. So I'm trying to get it so that I have multiple CS files for this web service that have the different attribute URLs hardcoded in them, and MSBuild swaps them on precompile. So I'd have a base "Service.cs" for testing, "Service.cs.production" for the production environment, and so on.
Thanks!
Upvotes: 2
Views: 2212
Reputation: 6145
In conjunction with Defining constants, and using #if directives,
You can also write a custom build task -> Target BeforeBuild, then using the Engine.GlobalEngine.GetLoadedProject("projpath") in to Project object.
Now you can manipulate the properties on the Project object however you want for different environments.
Consider adding Platforms in the configuration, for different environments if you want to.
This may not be the answer you are looking for, but something to consider when you want to fork build based on project environments.
Upvotes: 3
Reputation: 9258
Could you use conditional comments?
#if TESTING
[SoapDocumentMethodAttribute(something)]
#else
[SoapDocumentMethodAttribute(someotherthing)]
#endif
For your test configuration you would define the constant:
<DefineConstants>TESTING</DefineConstants>
Upvotes: 4