Visual Studio安装程序-更改应用程序资源 [英] Visual Studio Installer -- Change application resource

查看:82
本文介绍了Visual Studio安装程序-更改应用程序资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我的Resources.resx文件中包含用于主窗口标题的资源的应用程序.我将此绑定到我的主要Windows标题

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

我有2个安装程序(每个客户一个).我现在是这样的:

  1. 设置特定于客户端A的标题.
  2. 编译应用程序.
  3. 为客户端A构建安装文件.
  4. 设置特定于客户B的标题.
  5. 编译应用程序.
  6. 为客户端B构建安装文件.

是否可以将资源设置为特定于我使用的安装程序项目?然后,将值改回默认"值吗?

解决方案

我认为您可以执行以下操作:

1)创建两个名为Resources.ClientAResources.ClientB的程序集.它们应具有完全相同的内容(相同名称空间中的相同类),但是此内容应针对特定客户端特定于客户端.例如,我添加了以下课程只是为了说明:

// 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)打开您的主项目文件(csproj)并添加:

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

3)在下面的同一文件中添加引用:

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

现在,通过替换ClientToken属性,您可以替换客户端特定的程序集.您还可以在连续集成过程中指定此属性,但是可能需要稍微修改csproj文件,以便它将从外部获取此属性,并且只有在未设置该属性的情况下,才设置默认值.

我也不确定要完成任务的简便方法,也许有些.

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?

解决方案

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.

这篇关于Visual Studio安装程序-更改应用程序资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆