views:

1196

answers:

3

We are looking to provide two custom Platform switches (the platform dropdown in the configuration manager) for our projects in Visual Studio.

For example one for 'Desktop' and one for 'Web'. The target build tasks then compile the code in a custom way based on the platform switch. We don't want to add to the Debug Release switch because we would need those for each Desktop and Web platforms.

We found one way to attempt this, is to modify the .csproj file to add something like this

<Platform Condition=" '$(Platform)' == '' ">Desktop</Platform>

and add propertygroups like,

    <PropertyGroup Condition=" '$(Platform)' == 'Web' ">
        <DefineConstants>/define Web</DefineConstants>
        <PlatformTarget>Web</PlatformTarget>
      </PropertyGroup>
      <PropertyGroup Condition=" '$(Platform)' == 'Desktop' ">
        <DefineConstants>/define Desktop</DefineConstants>
        <PlatformTarget>Desktop</PlatformTarget>
      </PropertyGroup>

But still this doesn't work, and compiler throws an error

Invalid option 'Desktop' for /platform; must be anycpu, x86, Itanium or x64

So does it have to be one of those options and can't we add our custom platforms?

Has anyone been able to do this? any pointers would be helpful.

Update: Using DebugDesktop and ReleaseDesktop will make it more complicated for users. Because 'desktop' and 'web' are actually platforms and also there is ability to add new platforms in the dropdown (i.e. ), I believe 'platform' switch should be used for the exact same purpose.

A: 

Rename "Debug" and "Release" to "Debug Desktop" and "Release Desktop" and copy them into names "Debug Web" and "Release Web". Then set your constants up that way.

Joel Lucsy
So using platform switch isn't possible you mean?
Vin
+3  A: 

You should be able to use the Configuration Manager dialog to create new platforms.

Scott Dorman
+1  A: 

I've recently asked the same question and it appears that with Visual Studio 2010 you can define your own project platforms. (See http://blogs.msdn.com/b/vcblog/archive/2008/11/20/printf-hello-msbuild-n.aspx). Unfortunately, we are still using 2008.

Gordon