【发布时间】:2008-11-05 17:51:10
【问题描述】:
我们希望为 Visual Studio 中的项目提供两个自定义平台开关(配置管理器中的平台下拉菜单)。
例如,一个用于“桌面”,一个用于“Web”。然后目标构建任务基于平台切换以自定义方式编译代码。我们不想添加到 Debug Release 开关,因为每个桌面和 Web 平台都需要这些开关。
我们找到了一种尝试方法,即修改 .csproj 文件以添加类似的内容
<Platform Condition=" '$(Platform)' == '' ">Desktop</Platform>
并添加属性组,例如,
<PropertyGroup Condition=" '$(Platform)' == 'Web' ">
<DefineConstants>/define Web</DefineConstants>
<PlatformTarget>Web</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Platform)' == 'Desktop' ">
<DefineConstants>/define Desktop</DefineConstants>
<PlatformTarget>Desktop</PlatformTarget>
</PropertyGroup>
但这仍然不起作用,编译器会抛出错误
/platform 的“桌面”选项无效;必须是 anycpu、x86、Itanium 或 x64
那么它是否必须是这些选项之一,我们不能添加我们的自定义平台吗?
有人能做到吗?任何指针都会有所帮助。
更新:使用 DebugDesktop 和 ReleaseDesktop 会使用户更加复杂。因为“桌面”和“网络”实际上是平台,并且可以在下拉列表中添加新平台(即 ),我相信“平台”开关应该用于完全相同的目的。
【问题讨论】:
标签: c# visual-studio visual-studio-2008