How can I embed an configuration-specific manifest file in my c# app?

限于喜欢 提交于 2019-12-21 20:58:02

问题


I'd like to embed a platform-specific manifest file in my C# app. Is there an easy way to do this in Visual Studio 2008 without using some external script called after the build is finished?

In creating a C# app, the configuration and platform dropdowns are disabled for the Application tab, preventing me from selecting an architecture or configuration specific manifest to embed to that app. I'm forced to use one manifest for the whole application.

I thought of using a Post Build event to call a little script to embed the right manifest based on the $(Configuration) macro variable, and it works, but I want to do this without calling into some other script and I want to know if it's possible to do without using Build Events.

Can I embed the x86 and x64 assembly references in the same manifest file and the run time will just load the correct one?


回答1:


You simply need to add the app.manifest file. Right-click the project, select "Add" -> "New Item...". Select the "General" entry on the left tree view under "Visual C# Items". From the "Templates" list, locate and select the item call "Application Manifest File". Click Add.

Now you have a manifest, now let's make it platform specific. Right-click the project and select "Unload Project". Right-click again and select "Edit {project name}.csproj".

Locate the first configuration section, at the end you should find...

<PropertyGroup>
    ...
    <ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>

You need to move the ApplicationManifest element into the appropriate configuration section for the platform configuration. You may even need to add a section to the xml as I did here for AnyCPU:

<PropertyGroup Condition=" '$(Platform)' == 'AnyCPU' ">
    <ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>

When your finished, save the file, right-click the project, and select "Reload Project".



来源:https://stackoverflow.com/questions/6767999/how-can-i-embed-an-configuration-specific-manifest-file-in-my-c-sharp-app

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