MSBuild的条件编译条件、MSBuild

由网友(简美 ﹌)分享简介:我有框架的其余部分取决于抓住其数据的Web服务类,但Web服务类需要有不同的方法,属性取决于什么样的环境它在,例如... I have a web service class that the rest of the framework depends on to grab its data, but the web...

我有框架的其余部分取决于抓住其数据的Web服务类,但Web服务类需要有不同的方法,属性取决于什么样的环境它在,例如...

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
}

请参阅https://开头的例子?需要根据环境来改变。 AFAIK你不能使该字符串动态运行时,它必须被编译的方式。所以我好一会才让我有多个CS文件,该Web服务具有不同的属性,它们链接可硬codeD和MSBuild的交换他们在precompile。所以我有一个基地的Service.cs进行测试,Service.cs.production为生产环境,等等。

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.

这是做到这一点的最好办法,还是我失去了一些东西,我可以有一个CS处理自己?环境 要为preserve相同的类名和智能感知没有想到的事情是不明确的,我碴了文件扩展名(的Service.cs与Service.cs.production)。这是唯一的办法做到这一点? 在考虑到所有上述是确定的,而我对编制一个生产的配置,可以在编译,而不是Service.cs.production 的Service.cs,万事如意虎背熊腰,脚蹬 - 多雷? Is this the best way to do this, or am I missing something where I can have one CS that handles the environment on its own? To preserve having the same class name and IntelliSense not thinking things are ambiguous, I'm mucking up the file extensions ("Service.cs" versus "Service.cs.production"). Is that the only way to do it? Considering all the above is OK, and I'm compiling against a "Production" configuration, can it compile Service.cs.production instead of Service.cs and everything goes hunky-dorey?

谢谢!

推荐答案

你能使用条件注释?

#if TESTING
        [SoapDocumentMethodAttribute(something)]
#else
        [SoapDocumentMethodAttribute(someotherthing)]
#endif

有关测试的配置,你会定义常量:

For your test configuration you would define the constant:

<DefineConstants>TESTING</DefineConstants>
阅读全文

相关推荐

最新文章