问题
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:
- Set the title particular to client A.
- Compile the application.
- Build the installation file for client A.
- Set the title particular to client B.
- Compile the application.
- 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