none
MSBuild and its use of the "Platform" environment variable RRS feed

  • Question

  • Hi,
    I recently downloaded the source for an open source program (SharpDevelop) that calls MSBuild through a .bat to build the .exe. When I attempt to build it, the build fails with an "MSB4126: The specified solution configuration "Debug|HPD" is invalid" error.

    This is on a brand new HP Pavilion sysytem. I traced the problem down to the fact that HP defines the "Platform" enviroment variable as "Platform=HPD". I fixed the problem by adding "/p:Platform=Any CPU" to the MSBuild command line in the .bat file to override it.

    My question is this: Is the "Platform" enviroment variable defined for the use of MSBuild alone or does it have other uses in Windows besides setting the CPU platform?

    I have a similar question in to HP support to see if they use it for something in their installed OEM software when it runs. If possible, I'm looking to delete/clear it all together and let the default configuration in the solution file set the value.

    Thanks in advance.

    Paul

     

    • Edited by PMBottas Saturday, February 20, 2010 8:35 PM typo
    Saturday, February 20, 2010 8:33 PM

Answers

  • Mike,

    Thanks for the info. My workaround is fairly straight forward. In fact, it's probably more of a "best practices" solution besides. I just simply make sure that I define the "platform" property via a "/p:Platform=..." switch whenever I run MSBuild at the command line. (I did undef the enviro var as well though) 

    It's Randy, James and Martin (and I imagine others) who are experiencing the problem whenever they build inside the Expression Blend IDE who really have no recourse other than to undefine the Environment Variable definition of "platform".  (why do I get the feeling that EB is spawning a process to handle the build, whereas an VS build uses methods in namespace Microsoft.Build.* )

    And as I said before (above) "I am not the only one over the years who've run up against HP doing this. Just Bing/MSDN search/Google "Platform=HPD" or "Platform=BCP" and you'll see."

    As far as "raising a support case with HP", I have, back on 02/20/10 (it's HP "Service Ticket Number {ticketno:[8035679815]}" ). After going back and forth with several HP reps that day, who failed to understand the importance/implication of the problem (not surprisingly), the next day (02/21/10) I received an email from an HP rep named Anita, who stated: "Paul, in order to assist you in a better way, I am escalating your case to my supervisor and he will take care of the issue as soon as possible."

    I have yet to hear back from HP. Obviously, "as soon as possible" is very relative term.

    Do you, being an MS MVP, know of anyone at MS who could, shall we say, put a "bug in the ear" of someone at HP?

    Not necessarily regarding my ticket number per se, but the "is it safe to undefine the Environment Variable definition of "platform" issue (an perhaps, more importantly, "why are you doing it in the first place!"), on behalf of all of us, especially since it appears that anyone who uses EB  on an HP system is going to run up against this problem. (see the links in my post above on Sunday, April 25, 2010 4:31 AM) Those of us with my problem (invoking MSBuild at the command line) have a very simple resolution.

    Thanks for taking an interest in this.

    Paul

     

    Update: I just "re-Binged & re-Googled"  Platform=HPD and found out that my research is correct. "Platform=HPD" is apparently only used by "HP Easy Setup" - Can we (ie MS) file a "cease and desist" order against HP (or get them to design their setup software to delete the registry keys that define the var upon the first "normal" boot after the HP "final setup/product registration" is completed? This issue has been going on for YEARS. I find it hard to believe that HP has not been made aware of the conflict. (or prehaps when VS or EB is installed and it detects that it is on an HP box and Platform is defined, that VS/EB setup removes the registry keys)

     

     

    Tuesday, April 27, 2010 1:04 AM

All replies

  • Hi

    To answer your question - let me just take a moment to explain two main things that every .NET project has to support: Configuration and Platform. Normally we all know about the Configuration - this is nothing but what you define as Debug or Release mode i.e. the code that is compiled should it be compiled in a debug mode so that you can debug it at runtime or not. 

    Now coming to Platform : MSDN defines this attribute as - Specifies which version of the common language runtime (CLR) can run the assembly. Here is the link on this attribute - http://msdn.microsoft.com/en-us/library/zekwfyz4(VS.80).aspx.

    So answer for your question - Platform is a attribute used by C# compiler and it is a compiler option. So if you change the batch file or MSbuild
    script to change it to Any CPU should not be a problem. It will direct the compiler to build binaries to run on any platforms.

    Hope this answers your question.

    --------

    PS:If this solved your doubt/problem please mark this as answer.

    kashyapa
    Sunday, February 21, 2010 4:06 AM
  • Thank you for replying but I'm not sure that you understood my question.

    I have a basic understanding of the use of the Platform property (or /platform complier switch, if you prefer) and how it relates to a build in VS. I just recently went from an old Celeron rig to a AMD x64 quadcore based system. I've been reading about (& messing with) taking an x86 app and converting/building it as x64 one.
    (reading plus head scratching and a little bit of hair pulling as well - we're getting there though)

    Anyway....I'm not talking about the Platform property (well, indirectly I am) but rather if an ENVIRONMENT VARIABLE named "Platform" exists at the time MSBuild is invoked, the action that MSBuild takes with regards to the MSBuild's use of this variable. I know that environment variables can be used/referenced by project/solution files,  but I'm talking specifically about an environment variable call "Platform".

    It appears that MSBuild uses the value of the environment variable "Platform" as the value of the Platform property during a build of the target "ValidateSolutionConfiguration".

    And that's another question - what/where is the "ValidateSolutionConfiguration" target.
    Is it an sanity check target, something built into MSBuild that checks for valid values of the Configuration and Platform properties? I've searched the solution file that fails and this target does not appear to exist; in fact I checked my computer for the string "ValidateSolutionConfiguration" and it is not found anywhere!!!!.

    Like I said in my OP, Hewlett Packard computers (ie - my new rig) set the environment variable "Platform" to a value of "HPD" which is NOT a valid value for the Platform property. Hence when I run the .bat file that calls MSBuild, it promptly fails with a MSB4126 error: "The specified solution configuration "Debug|HPD"  is invalid - Done building target "ValidateSolutionConfiguration" in project SharpDevelop.sln-- FAILED"

    I resolved the issue by adding "/p:Platform=Any CPU" to the build command line in the .bat file. ( and I know, I know... "#D" you're saying to yourself?? - but don't worry - I'm not about to trade in VS any time soon, I'm just code browsing . In fact now that I've got a somewhat "real" system, I just downloaded VS2010RC... but I digress)


    BUT MY REAL QUESTION REMAINS:
    Is the "Platform" environment variable defined for the use of MSBuild alone or does it have other uses in Windows besides setting the CPU platform in an invocation of MSBuild ?

     

    Thanks - Paul

    Sunday, February 21, 2010 5:51 AM
  • Hi Paul,

    The definition of ValidateSolutionConfiguration target as following shows:

      <Target Name="ValidateSolutionConfiguration">
        <Error Text="The specified solution configuration &quot;$(Configuration)|$(Platform)&quot; is invalid. Please specify a valid solution configuration using the Configuration and Platform properties (e.g. MSBuild.exe Solution.sln /p:Configuration=Debug /p:Platform=&quot;Any CPU&quot;) or leave those properties blank to use the default solution configuration." Code="MSB4126" HelpKeyword="MSBuild.SolutionInvalidSolutionConfiguration" Condition="('$(CurrentSolutionConfigurationContents)' == '') and ('$(SkipInvalidConfigurations)' != 'true')" />
        <Warning Text="The specified solution configuration &quot;$(Configuration)|$(Platform)&quot; is invalid. Please specify a valid solution configuration using the Configuration and Platform properties (e.g. MSBuild.exe Solution.sln /p:Configuration=Debug /p:Platform=&quot;Any CPU&quot;) or leave those properties blank to use the default solution configuration." Code="MSB4126" HelpKeyword="MSBuild.SolutionInvalidSolutionConfiguration" Condition="('$(CurrentSolutionConfigurationContents)' == '') and ('$(SkipInvalidConfigurations)' == 'true')" />
        <Message Text="Building solution configuration &quot;$(Configuration)|$(Platform)&quot;." Condition="'$(CurrentSolutionConfigurationContents)' != ''" />
      </Target>
    And based on my understanding, the "Platform" environment variable defines with VS macro, is not only defined for MSBuild alone, it's used for solution level.

    If I misunderstood you, or you have any questions, please let me know.

    Best Regards,
    Nancy
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Tuesday, February 23, 2010 10:20 AM
  • Nancy,

    Thanks!

    I've been burning the midnight oil reading about MSBuild and last night around 2:00 am I came across the neat little trick of defining the environment variable "MSBuildEmitSolution=1" to have MSBuild write out to disk the contents of the internal project buffer that it creates when it does a solution build. So I define the variable, open the resulting .sln.proj file, and lo and behold, there is the target "ValidateSolutionConfiguration", word for word as you said!

    So I'm assuming that my musing was correct in that the ValidateSolutionConfiguration target is created internally by MSBuild when does a solution based build, because it does not appear in either the .sln file nor in any of the 20 odd .csproj files in the solution.

    Secondly, with regards the "Platform" environment variable, are you saying that, to the best of your knowledge, that it is strictly being used by MSBuild/VS and it is not something that is/was defined by the OS at install/setup time? If this is true then it is something that HP defines for it's own use in it's OEM OS installs and it just happens to conflict with the usage defined by MSBuild.

    I would really appreciate a definitive answer on this, if you or anyone else out there could provide me with one. (MSFT usage, not HP's)

    Thanks in advance,
    Paul

    Wednesday, February 24, 2010 12:25 AM
  • Hi Paul,

    Based on my understanding, MSBuild just support these kinds of platforms: x86, Itanium, x64, or anycpu (default). It does not support Platform:HPD. For more information, please see:

    /platform (Visual Studio - JScript) 

    When you use MSBuild to build project file, you'd better pass platform parameter to MSBuild ( if you build .sln it will be included in .sln file), or MSBuild will be builded with Debug|Any CPU, you can refer to the solution cache file by setting MSBuildEmitSolution=1, please note following code:

      <PropertyGroup Condition=" '$(Configuration)' == '' ">
        <Configuration>Debug</Configuration>
      </PropertyGroup>
      <PropertyGroup Condition=" '$(Platform)' == '' ">
        <Platform>Any CPU</Platform>
      </PropertyGroup>
    For your reference, please see:

    Visual Studio .NET Platform Target Explained
    http://vsh.infozerk.net/articles/visual-studio-net-platform-target-explained/

    Best Regards,
    Nancy
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Wednesday, February 24, 2010 9:03 AM
  • Nancy,
    Yes, I'm aware that Platform:HPD is invalid.
    That's what started this whole discussion in the first place :)

    It's also the what and why of the questions I put to Hewlett-Packard support: 
    '"Why are you defining an enviro var 'Platform=HPD'?
    "Are you aware of the conflict it can cause with MSBuilld's platform property?"
    "Can I undefine it with no ill effects on HP software?"

    And Yes, I'm also aware that "/p:platform=..." can be defined on the MSBuild command line to override the enviro definition
    That's how I resolved the initial problem!!!.
    (The supplied .bat file that calls MSBuild wasn't doing this - see my OP & 1st reply)

    This thread was spurred by the fact that I'm concerned that if I remove the key/data pair from the ...\Environment registry key so that it isn't defined every time I boot, that some of HP's software won't work - mainly the HP automatic update software or a patch installer, not MSBuild use of the platform property or why Platform=HPD is invalid. (Figuring out what the heck target ValidateSolutionConfiguration was and where it came from was just a bonus! Thanks.)

    This is why I wanted to know if the "Platform" enviro var is/was defined by Windows OS at install and is being used by other Microsoft products (other than MSBuild/VS) or does HP define it and they are just blind to MSBuild's use of it?

    Other than in several registry keys:
    HKEY_LOCAL_MACHINE\SOFTWARE\Hewlett-Packard\HPLocale,
    HKEY_LOCAL_MACHINE\SOFTWARE\Hewlett-Packard\System Properties,
    HKEY_LOCAL_MACHINE\SOFTWARE\Hewlett-Packard\SystemProperties
    plus the one I'm interested in, (HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment (and ...\ControlSet001\... & 002) where it's defined for persistence) and in two log files, I did find that "Platform=HPD" was being used in one of HP's .bat files that is used to install some optional software that comes with the OEM setup, so they are doing something with it. Whether or not that something is just usage at the OEM OS "first-boot/finishing setup" and HP product registration process and can now be safely undefined is the crux of the questions I have into HP right now. I figure that if they have it defined in the SystemProperties registry keys but are still defining it as an environment variable that they must be referencing it in scripts, but defining it for just one script at OEM setup time when they must know what HP product model & Microsoft OS they installing it on seems a little overkill IMHO.

    I'm just trying to find out the usage of it on the Microsoft end of things, if there is any, other than MSBuild.

    Should I repost this question to a different forum?

    Like I've said before, I am not the only one over the years who've run up against HP doing this.
    Just Bing/MSDN search/Google "Platform=HPD" or "Platform=BCP" and you'll see.

    I've yet to hear back from HP support as to why they define "Platform=HPD", (other than to say that they're "escalating the support case to the managerial level"- which says to me "we have no idea, now go away"), so for now I'm going to leave it alone (i.e. not delete the key/data pair from the registry) in case they are using it for some other reason and just make sure that I define the "configuration" & "platform" properties on the MSBuild command line.
    That's probably the "best practices" way of doing this anyway.


    --------

    BOTTOM LINE:
    My initial question still remains unanswered - Is the "Platform" environment variable defined for the use of MSBuild alone or does it have other uses in Windows besides setting the CPU platform?

    Since it appears in the HKEY_LOCAL_MACHINE\SOFTWARE\Hewlett-Packard\SystemProperties reg key, I'm getting the feeling that it's HP's animal not Microsoft's

    Anyone one else have a answer/opinion on this?
    (...also anybody out there with a non-HP box that has an OEM installed version of Windows and could/would check to see it it's defined on their system would be a big help..).

    Since I'm now well versed in MSBuild's use of it, should I repost elsewhere?
    If so, where?

    On another MSDN forum?

    One on TechNet?

    If anyone who reads this knows where I should repost, please, please reply.

    Thanks in advance,
    Paul

    Wednesday, February 24, 2010 7:16 PM
  • Paul,

    I have the same issue "Debug|HPD" is invalid when I try to build anything with BLEND 4 BETA on both of my HP machines. I can run the project from VS but not blend. I'd love to fix the problem with Platform'"Any CPU" but I have no clue where to find this.

    Any help would be greatly appreciated.

    Thanks,

    Randy

     

    Saturday, April 24, 2010 8:40 PM
  • Randy,

    I'm not familiar with BLEND (I'm still using WinForms, I have yet to make the jump to WPF), but as I stated above, the problem stems from the fact that HP defines the environment variable "Platform" to a value that conflicts with MSBuild's use of the variable. If you've read my above post dated Wednesday, February 24, 2010 7:16 PM, you'll see that I've put in a support case to HP to see if I undefine "Platform", if it will cause any problems. I have never received a reply from them, despite that fact that the case was "escalated".

    I resolved the issue by making sure that when I run MSBuild from a command window prompt  (which is when the problem arises) that I make sure that I add a "/p:Platform=Any CPU" switch to the MSBuild command line, which overrides the environment definition.

    But since BLEND is an IDE environment and you are getting the error when you build from within the IDE, I'm not sure how you would go about defining "Platform" in it (in fact it probably already IS defined and the enviro def is overriding it).

    You could take the route that I originally wanted to do and undefine the enviro def.  I did this a while back and haven't had any problems when the HP Support Assistant runs and update my HP software. I did a fairly exhaustive search of my system (.bat, .cmd files  etc) to see  where HP was using this variable and it appears that it is only used during the initial system setup and HP product registration.

    Do you know how to define/undefine a environment variable?

    Paul

    • Edited by PMBottas Sunday, April 25, 2010 2:48 AM typo (per usual)
    Sunday, April 25, 2010 2:19 AM
  • Paul,

    That did the trick. Thanks so much!

    Randy

     

    Sunday, April 25, 2010 3:20 AM
  • Randy,

    You're not the only EB user with this problem!

    See:

    http://social.expression.microsoft.com/Forums/en-US/blend/thread/71496590-a9ec-4e3a-8353-3ced345f78dc  and

    http://social.expression.microsoft.com/Forums/en-US/blend/thread/a67e05e8-28f7-4516-a0c2-78787f38e12e

    I just wish if I knew if it was truly "safe" to undef platform=HPD!

     But us, just being mere mortals, we seem to get ignored (at/from HP, that is - maybe if you, James, Martin and myself hit HP with the same support case question on the same day, somebody at HP would notice us...)

    What we really need is an MS MVP (or somebody with similar "pull") to find out from MS/HP (and apparently other manufacturers according to Martin's posts) if this is safe to do

    (hello moderators - is anyone listening?)

    happy coding...

    Paul

    Sunday, April 25, 2010 4:31 AM
  • Hi Paul

    I encountered the same issue a few years back (searching my archives brings up nothing unfortunately). It wasn't an HP, but the same problem with anEnvironment Variable from the manufacturer clashing with the Visual Studio build system. I think the workaround was to delete the environment variable and then everything worked as intended. This should be safe to do so long as you aren't using some of the pre-installed apps that HP installs and they perhaps need the environment variable. Given your research though, it looks like you may be safe to do so.

    It may be helpful in the long run if you raise a support case with HP so they become aware of the issues that their use of a 'reserved' environment variable is causing.

    Mike

     


    Visual Studio ALM MVP
    My Blog | MSBuild Extension Pack | MSBuild Explorer
    Monday, April 26, 2010 9:18 AM
    Moderator
  • Hi,

    I think there is no need in deleting the global environment variable. Only IDE or VS command prompt have to have this variable cleared up. What could help is just adding SET PLATFORM= in vcvarsall.bat for VS command line prompt or creating a small bat file which would clear up PLATFORM and run devenv for IDE.

    Cheers,
    Ilya

    • Proposed as answer by obas Thursday, February 21, 2013 4:04 PM
    Tuesday, April 27, 2010 12:19 AM
  • Mike,

    Thanks for the info. My workaround is fairly straight forward. In fact, it's probably more of a "best practices" solution besides. I just simply make sure that I define the "platform" property via a "/p:Platform=..." switch whenever I run MSBuild at the command line. (I did undef the enviro var as well though) 

    It's Randy, James and Martin (and I imagine others) who are experiencing the problem whenever they build inside the Expression Blend IDE who really have no recourse other than to undefine the Environment Variable definition of "platform".  (why do I get the feeling that EB is spawning a process to handle the build, whereas an VS build uses methods in namespace Microsoft.Build.* )

    And as I said before (above) "I am not the only one over the years who've run up against HP doing this. Just Bing/MSDN search/Google "Platform=HPD" or "Platform=BCP" and you'll see."

    As far as "raising a support case with HP", I have, back on 02/20/10 (it's HP "Service Ticket Number {ticketno:[8035679815]}" ). After going back and forth with several HP reps that day, who failed to understand the importance/implication of the problem (not surprisingly), the next day (02/21/10) I received an email from an HP rep named Anita, who stated: "Paul, in order to assist you in a better way, I am escalating your case to my supervisor and he will take care of the issue as soon as possible."

    I have yet to hear back from HP. Obviously, "as soon as possible" is very relative term.

    Do you, being an MS MVP, know of anyone at MS who could, shall we say, put a "bug in the ear" of someone at HP?

    Not necessarily regarding my ticket number per se, but the "is it safe to undefine the Environment Variable definition of "platform" issue (an perhaps, more importantly, "why are you doing it in the first place!"), on behalf of all of us, especially since it appears that anyone who uses EB  on an HP system is going to run up against this problem. (see the links in my post above on Sunday, April 25, 2010 4:31 AM) Those of us with my problem (invoking MSBuild at the command line) have a very simple resolution.

    Thanks for taking an interest in this.

    Paul

     

    Update: I just "re-Binged & re-Googled"  Platform=HPD and found out that my research is correct. "Platform=HPD" is apparently only used by "HP Easy Setup" - Can we (ie MS) file a "cease and desist" order against HP (or get them to design their setup software to delete the registry keys that define the var upon the first "normal" boot after the HP "final setup/product registration" is completed? This issue has been going on for YEARS. I find it hard to believe that HP has not been made aware of the conflict. (or prehaps when VS or EB is installed and it detects that it is on an HP box and Platform is defined, that VS/EB setup removes the registry keys)

     

     

    Tuesday, April 27, 2010 1:04 AM
  • Ilya,

    That's a nice clean, solution!

    Will this work as it relates to/for the problem the EB users are expriencing when building within the EB IDE itself? (as I stated I don't have EB - just may download the trial just to mess with this)

    Paul

    Tuesday, April 27, 2010 1:24 AM
  • Hi Paul,

    The definition of ValidateSolutionConfiguration target as following shows:

     <Target Name="ValidateSolutionConfiguration">
      <Error Text="The specified solution configuration "$(Configuration)|$(Platform)" is invalid. Please specify a valid solution configuration using the Configuration and Platform properties (e.g. MSBuild.exe Solution.sln /p:Configuration=Debug /p:Platform="Any CPU") or leave those properties blank to use the default solution configuration." Code="MSB4126" HelpKeyword="MSBuild.SolutionInvalidSolutionConfiguration" Condition="('$(CurrentSolutionConfigurationContents)' == '') and ('$(SkipInvalidConfigurations)' != 'true')" />
      <Warning Text="The specified solution configuration "$(Configuration)|$(Platform)" is invalid. Please specify a valid solution configuration using the Configuration and Platform properties (e.g. MSBuild.exe Solution.sln /p:Configuration=Debug /p:Platform="Any CPU") or leave those properties blank to use the default solution configuration." Code="MSB4126" HelpKeyword="MSBuild.SolutionInvalidSolutionConfiguration" Condition="('$(CurrentSolutionConfigurationContents)' == '') and ('$(SkipInvalidConfigurations)' == 'true')" />
      <Message Text="Building solution configuration "$(Configuration)|$(Platform)"." Condition="'$(CurrentSolutionConfigurationContents)' != ''" />
     </< span>Target>
    
    And based on my understanding, the "Platform" environment variable defines with VS macro, is not only defined for MSBuild alone, it's used for solution level.

    If I misunderstood you, or you have any questions, please let me know.

    Best Regards,
    Nancy
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.

    Anybody can tell me what's the problem? Why your way does not work for me?
    Monday, August 16, 2010 12:14 AM
  • I just saw this but it was on a Lenovo and the platform was set to BWD or something, however, I am not sure if Lenovo or our internal IT team did this or how it got this way.

    I deleted the environment variable.

     


    http://www.rhyous.com
    Thursday, October 13, 2011 6:53 PM
  • Hi PMBottas
    i read your post here and I am very much a novice in coding and the likes so i have little understanding of what you are saying... i am currently trying to code c++ but without a builder/debugger its hard to identify if i have errors or if the code even works... so i have a shortish question:

    Couldn't we just resolve this if we made some code which allowed us to manually select the Platform Environment variable that we want to use?
    for example:"

    if platform = HPD then do x "
    where x is a popup that allows you to manually choose which platform you are using and overrides the applications conditional code that determines what you platform is
    is this a possible solution?
    -i'm asking this because i need a solution to this HPD variable and i dont want to go and reassign the variable for my whole computer as i dont want any programs to be adversely affected. also i have no clue how to fix the problem myself lol.

    clearly HP isnt going to get around to anything like this anytime soon so we come back to 'if you want something done, you gotta do it yourself' kind of scenario... 

    -if you dont like this post feel free to report it as 'Off topic/irrelevant posts'

    Saturday, July 20, 2019 7:56 AM