合并与它的配置.NET应用程序 [英] Merging .NET application with its configuration

查看:125
本文介绍了合并与它的配置.NET应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个.NET的可执行文件。

I have a .NET executable.

有关此可执行文件,我需要将它与它的配置合并在一起,得到的只有一个文件。

For this executable, I need to merge it together with its configuration to get only one file.

这配置可以是任何东西,不仅app.config文件,它是静态的,合并后不会改变。但是,这将是合并前的动态。所以,我可以结束了很多可执行文件各有不同的配置内置的

This configuration can be anything, not only app.config file and it is static and will never change after merging. But it will be dynamic before merging. So I can end up with many executables each with different configuration build-in.

合并过程将programaticaly运行,以配置作为参数,并需要在相当快的。

The merging process will be run programaticaly, with configuration being parameters and needs to be reasonably fast.

任何人都有类似的问题?我想使用ILMerge的资源合并,但我不知道它是否能做到这一点。或者我可以建立整个exacutable与devenv的,这需要的VisualStudio可以在PC上安装的,也就是合并,这将不总是这种情况。而且我不认为这将是速度不够快。

Anyone had similiar problem? I was thinking about merging using ILMerge with resources, but I dont know if it can do it. Or I can build whole exacutable with devenv, this requires VisualStudio to be installed on the PC, that is merging, which will not always be the case. And I don't think it will be fast enough.

编辑: 经过四处寻找第二和尝试的东西,也许Mono.Cecil能做到可以做的工作。在我的可执行文件,我将创建一个静态的配置类,这将有物业,我的配置。而使用IL重写,我将改变这些属性返回。这个任何意见?

After looking around for a second and trying something, maybe Mono.Cecil can do the work. In my executable, I will create a static Configuration class, which will have properties with my configuration. And using IL rewrite, I will change what those properties return. Any opinions about this?

推荐答案

您可以更改文件,以嵌入的资源,并复制到输出,以虚假的构建属性。然后,获得配置信息,用code是这样的:

You can change the build property of the file to Embedded Resource and the Copy to Output to false. Then, to get the config info, use code like this:

string ReadEmbeddedResource(string fileName) {
  Assembly app = Assembly.GetExecutingAssembly();

  // This will be the fully-qualified name
  Stream resource = app.GetManifestResourceStream(app.GetName().Name + "." + fileName);

  StreamReader reader = new StreamReader(resource);
  return reader.ReadToEnd();        
}

现在,app.config文件不应再被复制到您的构建目录,你仍然可以从您的exe文件中引用。

Now, the app.config file should no longer be copied to your build directory and you can still reference from within your exe.

这篇关于合并与它的配置.NET应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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