none
renaming app.config or referring it from subfolder RRS feed

  • Question

  • We have decided to upgrade our project from .NET 4.0 to 4.5.2 but want to keep support of .Net 4.0 as it is.

    So we have created copy of each CSPROJ file in the same directory one for 4.0 and and other for 4.5.2, but they are referring to same app.config file. 

    How can I have 2 app.config files for each project?

    Tuesday, February 9, 2016 9:17 AM

Answers

  • How can I have 2 app.config files for each project?

    No. I think you cannot do this. Someone submit similar requirement in UserVoice, you can refer to see http://visualstudio.uservoice.com/forums/121579-visual-studio-2015/suggestions/2051965-allow-a-project-to-target-multiple-frameworks-ful There is no plan to support this feature as I know.

    In this case, I would suggest you use add as link feature to share source code to different framework target. Some simple steps for "Add as Link" in visual studio.

    • source code in one project
    • use add as link in another project

    For more info, please refer to https://msdn.microsoft.com/library/9f4t9t92(v=vs.100).aspx

    I hope it helps.

    Regards,


    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.

    Wednesday, February 10, 2016 7:30 AM
    Moderator
  • Set the AppConfig property in each csproj file. If the app.config contains assembly redirections that the compiler needs to care about, then set also the UseAppConfigForCompiler or AppConfigForCompiler property as mentioned at /appconfig (C# Compiler Options).

      <PropertyGroup>
        <!-- other properties -->
        <AppConfig>Sample-App.config</AppConfig>
      </PropertyGroup>

    See Microsoft.Common.targets and Microsoft.CSharp.targets for how these properties are used.

    If you do not set the AppConfig property, then the PrepareForBuild target in Microsoft.Common.targets runs the FindAppConfigFile task to set it. Microsoft has posted the source code of one version of FindAppConfigFile to GitHub: FindAppConfigFile.cs. The algorithm is:

    1. If an "app.config" file in the project root directory has Build Action = None, choose that.
    2. Otherwise, if an "app.config" file in the project root directory has Build Action = Content, choose that.
    3. Otherwise, if an "app.config" file anywhere in the project has Build Action = None, choose that.
    4. Otherwise, if an "app.config" file anywhere in the project has Build Action = Content, choose that.

    Thus, if you don't want to set the AppConfig properties by editing the csproj files, then you could instead create two subdirectories, add an "app.config" file in each subdirectory, and include those "app.config" files in the respective projects.

    Wednesday, February 10, 2016 4:24 PM

All replies

  • How can I have 2 app.config files for each project?

    No. I think you cannot do this. Someone submit similar requirement in UserVoice, you can refer to see http://visualstudio.uservoice.com/forums/121579-visual-studio-2015/suggestions/2051965-allow-a-project-to-target-multiple-frameworks-ful There is no plan to support this feature as I know.

    In this case, I would suggest you use add as link feature to share source code to different framework target. Some simple steps for "Add as Link" in visual studio.

    • source code in one project
    • use add as link in another project

    For more info, please refer to https://msdn.microsoft.com/library/9f4t9t92(v=vs.100).aspx

    I hope it helps.

    Regards,


    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.

    Wednesday, February 10, 2016 7:30 AM
    Moderator
  • Set the AppConfig property in each csproj file. If the app.config contains assembly redirections that the compiler needs to care about, then set also the UseAppConfigForCompiler or AppConfigForCompiler property as mentioned at /appconfig (C# Compiler Options).

      <PropertyGroup>
        <!-- other properties -->
        <AppConfig>Sample-App.config</AppConfig>
      </PropertyGroup>

    See Microsoft.Common.targets and Microsoft.CSharp.targets for how these properties are used.

    If you do not set the AppConfig property, then the PrepareForBuild target in Microsoft.Common.targets runs the FindAppConfigFile task to set it. Microsoft has posted the source code of one version of FindAppConfigFile to GitHub: FindAppConfigFile.cs. The algorithm is:

    1. If an "app.config" file in the project root directory has Build Action = None, choose that.
    2. Otherwise, if an "app.config" file in the project root directory has Build Action = Content, choose that.
    3. Otherwise, if an "app.config" file anywhere in the project has Build Action = None, choose that.
    4. Otherwise, if an "app.config" file anywhere in the project has Build Action = Content, choose that.

    Thus, if you don't want to set the AppConfig properties by editing the csproj files, then you could instead create two subdirectories, add an "app.config" file in each subdirectory, and include those "app.config" files in the respective projects.

    Wednesday, February 10, 2016 4:24 PM