Visual Studio Installer — Change application resource

我的未来我决定 提交于 2020-01-25 01:21:31

问题


Basically, I have my application with a resource for the title of the main window in my Resources.resx file. I bind this to my main windows title

Title={Binding Title, FallbackValue='My Generic Title'}

I have 2 installers (one for each of my clients). This is how I do it right now:

  1. Set the title particular to client A.
  2. Compile the application.
  3. Build the installation file for client A.
  4. Set the title particular to client B.
  5. Compile the application.
  6. Build the installation file for client B.

Is there any way to set the resource to be particular to the installer project I use? Then, afterwards, change the value back to a "default" value?


回答1:


I think you can do the following:

1) Create two assemblies named Resources.ClientA and Resources.ClientB. They should have exactly the same content (same classes in the same namespaces) but this content should be client-specific for corresponding clients. For example I've added following class just for illustration:

// assembly for ClientA : 
namespace Resources
{
    public class Class1
    {
        public static string Text { get { return "Client A text"; } }
    }
}

// assembly for ClientB : 
namespace Resources
{
    public class Class1
    {
        public static string Text { get { return "Client B text"; } }
    }
}

2) Open your main project file (csproj) and add:

<PropertyGroup>
    <ClientToken>ClientA</ClientToken>
</PropertyGroup>

3) In the same file below add the reference:

<ItemGroup>
    <ProjectReference Include="..\Resources.$(ClientToken)\Resources.$(ClientToken).csproj">
        <Name>Resources.$(ClientToken)</Name>
    </ProjectReference>
</ItemGroup>

Now by replacing the ClientToken property you can substitute client specific assemblies. You will also be able to specify this property as part of continuous integration process but probably you will need to modify your csproj file a bit so it will take this property from outside and only if it is not set then set some default value.

Also I'm not sure about easier ways to accomplish your task, probably there are some.



来源:https://stackoverflow.com/questions/6034381/visual-studio-installer-change-application-resource

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!