locked
Application Settings Based on Configuration Condition in Project File RRS feed

  • Question

  • Our team has a single VB.NET project from which we compile two separate products. In doing so, we have customized the *.vbproj file to use Choose/When items to conditionally include certain references based on the selected configuration. This is working well, although we have to be careful when editing the project file via Visual Studio since the IDE doesn't support all of this.

    Where we are having a problem is in setting some of the application settings, such as the RootNamespace, ApplicationIcon, StartupObject, and AssemblyName. We have tried a couple methods of setting these in the *.vbproj file based on the selected configuration, but when opening the project Visual Studio doesn't seem to read these. Below is an example of what we're trying to do.

    <PropertyGroup>
        <!--Set ROOTNAMESPACE-->
        <RootNamespace Condition=" '$(Configuration)' == 'Debug-Product1' ">Product1</RootNamespace>
        <RootNamespace Condition=" '$(Configuration)' == 'Debug-Product2' ">Product2</RootNamespace>
        <RootNamespace Condition=" '$(Configuration)' == 'Release-Product1' ">Product1</RootNamespace>
        <RootNamespace Condition=" '$(Configuration)' == 'Release-Product2' ">Product2</RootNamespace>
        <!--SET ASSEMBLY NAME-->
        <AssemblyName Condition=" '$(Configuration)' == 'Debug-Product1' ">Product1</AssemblyName>
        <AssemblyName Condition=" '$(Configuration)' == 'Debug-Product2' ">Product2</AssemblyName>
        <AssemblyName Condition=" '$(Configuration)' == 'Release-Product1' ">Product1</AssemblyName>
        <AssemblyName Condition=" '$(Configuration)' == 'Release-Product2' ">Product2</AssemblyName>
        <!--SET STARTUPOBJECT NAME-->
        <StartupObject Condition=" '$(Configuration)' == 'Debug-Product1' ">Product1.My.MyApplication</StartupObject>
        <StartupObject Condition=" '$(Configuration)' == 'Debug-Product2' ">Product2.My.MyApplication</StartupObject>
        <StartupObject Condition=" '$(Configuration)' == 'Release-Product1' ">Product1.My.MyApplication</StartupObject>
        <StartupObject Condition=" '$(Configuration)' == 'Release-Product2' ">Product2.My.MyApplication</StartupObject>
        <!--SET APPLICATION ICON-->
        <ApplicationIcon Condition=" '$(Configuration)' == 'Debug-Product1' ">Images\Icons\Product1.ico</ApplicationIcon>
        <ApplicationIcon Condition=" '$(Configuration)' == 'Debug-Product2' ">Images\Icons\Product2.ico</ApplicationIcon>
        <ApplicationIcon Condition=" '$(Configuration)' == 'Release-Product1' ">Images\Icons\Product1.ico</ApplicationIcon>
        <ApplicationIcon Condition=" '$(Configuration)' == 'Release-Product2' ">Images\Icons\Product2.ico</ApplicationIcon>
    </PropertyGroup>

    If we explicitly set these four application settings without the condition and open the project, it opens with the expected settings for whichever product we put in. Currently to switch between products our developers have to set the project file to writeable and modify the settings back and forth between the two products, depending on which one they want to debug. This is a pain and in certain cases results in the file getting checked in with the wrong settings.

    Since the configuration conditions are working for the references and other items in the project, we know that the configurations are ok. Perhaps it is the order in which things are read from the solution and/or project files? If anyone has any ideas on how to make this work it would be much appreciated.

    Thanks,
    Brady


    - Brady My posts are kept as simple as possible for easier understanding. In many cases you can probably optimize or spruce up what I present. Have fun coding!

    Thursday, July 30, 2015 12:26 AM

Answers

  • Hello HomeGrownCoder,

    IDE may not able to help you solve this issue. MSBuild forum is better.

    Please read the following about the PropertyGroup:

    https://msdn.microsoft.com/en-us/library/ms164307.aspx

    So what about consider doing something like this:

    <PropertyGroup Condition="'$(CompileConfig)' == 'DEBUG'" > <Optimization>false</Optimization> <Obfuscate>false</Obfuscate> <OutputPath>$(OutputPath)\debug</OutputPath> 

    ......

    <RootNamespace>Product1</RootNamespace> </PropertyGroup>

    Here set the property in the propertyGroup, and then use your configuration so that Visual Studio can specify your property.

    Best regards,

    Barry


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Proposed as answer by Jamles Hez Monday, August 10, 2015 7:09 AM
    • Marked as answer by Jamles Hez Tuesday, August 11, 2015 5:35 AM
    Tuesday, August 4, 2015 3:09 AM

All replies

  • Hi Brady,

    This forum is about Visual Studio IDE, as your issue is about your vb.net project, I'm afraid it is not related to Visual Studio IDE, it would be related to Visual Basic, I help you move this case to visual basic forum for dedicated support.

    Best Regards,

    Jiayi Li


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.

    Click HERE to participate the survey.

    Thursday, July 30, 2015 3:04 AM
  • Hi Jiayi,

    While my question refers to our project as being in VB, the project file, as far as I know, uses a common format in the various different languages, so this question is not specific to VB...I suspect the answer (if there is one) will apply to multiple languages. I put the question in the IDE forum since the issue appears to be with the Visual Studio IDE not correctly processing or interpreting the project file correctly.

    Regards,
    Brady


    - Brady My posts are kept as simple as possible for easier understanding. In many cases you can probably optimize or spruce up what I present. Have fun coding!

    Thursday, July 30, 2015 4:42 AM
  • Mr. Monkeyboy,

    Thank you for your reply, but we are already successfully doing as much as is shown in the example that you pointed to. Our issue is specifically with the few settings that I mentioned. Other items in the project file are processed as expected, using the condition based on the configuration.

    Thanks,
    Brady


    - Brady My posts are kept as simple as possible for easier understanding. In many cases you can probably optimize or spruce up what I present. Have fun coding!

    Thursday, July 30, 2015 4:45 AM
  • I'm not sure why this would be better asked in the WWF forum. I originally posted it in the Visual Studio IDE forum since it appears to be an issue with Visual Studio not understanding/reading the conditional statements in the project file.

    - Brady My posts are kept as simple as possible for easier understanding. In many cases you can probably optimize or spruce up what I present. Have fun coding!

    Thursday, July 30, 2015 7:04 PM
  • As far as I know, the Condition argument is a part of MSBuild. When we make the build via the command line, passing in the desired configuration, it compiles what we expect. The issue seems to be limited to the Visual Studio IDE not handling this as expected. This is why I originally posted in the Visual Studio IDE forum. It'd be great if this could get moved back over there, but I don't see how I can move it.

    - Brady My posts are kept as simple as possible for easier understanding. In many cases you can probably optimize or spruce up what I present. Have fun coding!

    Thursday, July 30, 2015 9:22 PM
  • Hello HomeGrownCoder,

    IDE may not able to help you solve this issue. MSBuild forum is better.

    Please read the following about the PropertyGroup:

    https://msdn.microsoft.com/en-us/library/ms164307.aspx

    So what about consider doing something like this:

    <PropertyGroup Condition="'$(CompileConfig)' == 'DEBUG'" > <Optimization>false</Optimization> <Obfuscate>false</Obfuscate> <OutputPath>$(OutputPath)\debug</OutputPath> 

    ......

    <RootNamespace>Product1</RootNamespace> </PropertyGroup>

    Here set the property in the propertyGroup, and then use your configuration so that Visual Studio can specify your property.

    Best regards,

    Barry


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Proposed as answer by Jamles Hez Monday, August 10, 2015 7:09 AM
    • Marked as answer by Jamles Hez Tuesday, August 11, 2015 5:35 AM
    Tuesday, August 4, 2015 3:09 AM