<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>dipplum.com &#187; Windows</title>
	<atom:link href="http://dipplum.com/category/computer/windows/feed/" rel="self" type="application/rss+xml" />
	<link>http://dipplum.com</link>
	<description>Be  the change you wanna see in the world</description>
	<lastBuildDate>Sat, 12 Nov 2011 07:38:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Visual C++编译环境免安装命令行版</title>
		<link>http://dipplum.com/2009/11/13/visualc-compiler-portable/</link>
		<comments>http://dipplum.com/2009/11/13/visualc-compiler-portable/#comments</comments>
		<pubDate>Fri, 13 Nov 2009 12:05:12 +0000</pubDate>
		<dc:creator>li</dc:creator>
				<category><![CDATA[Windows]]></category>
		<category><![CDATA[scons]]></category>
		<category><![CDATA[side-by-side]]></category>
		<category><![CDATA[visualc]]></category>

		<guid isPermaLink="false">http://dipplum.com/2009/11/13/visual-c%e7%bc%96%e8%af%91%e7%8e%af%e5%a2%83%e5%85%8d%e5%ae%89%e8%a3%85%e5%91%bd%e4%bb%a4%e8%a1%8c%e7%89%88/</guid>
		<description><![CDATA[VC的IDE开发环境很好，但太大了，经常是2005/2008/2010装一大堆，占用几十G的空间。用惯了Linux的命令行方式，觉得小巧精致。于是想把VC的基本命令提取出来，也做一个绿色版本。 保留基本的编译命令，cl、lib、link、ml之类的。编译工程只能用nmake了。vcproj工程文件怎么办？用scons重写一个吧。(其实命令行也有个vcbuild)。 制作绿色版之前，首先要安装一个VC，再把其中用到的文件提取出来。或者直接快进到后面找下载链接。 Visual C++ 2008制作要领 VC 2008的最大问题是Visual Studio采用Side-by-Side方式发布，不能简单的把依赖的DLL着全就行了。 1. 复制C:\Program Files\Microsoft Visual Studio&#160; 9.0\VC\bin及其子目录1033，到新的vc9\bin目录 2. 在复制VC目录下的lib和include目录，到新的vc9目录下 3. 复制C:\Program Files\Microsoft Visual Studio 2008\Common7\IDE目录下的：msobj80.dll，mspdb80.dll, mspdbcore.dll, mspdbsrv.exe到vc9\bin 4. 在vc\bin生成manifest文件，名为Micrisoft.VC90.CRT.manifest，内容如下 &#60;?xml version=&#34;2.0&#34; encoding=&#34;UTF-8&#34; standalone=&#34;yes&#34;?&#62; &#60;assembly xmlns=&#34;urn:schemas-microsoft-com:asm.v1&#34; manifestversion=&#34;1.0&#34;&#62; &#60;noinheritable&#62;&#60;/noinheritable&#62; &#60;assemblyidentity name=&#34;Microsoft.VC90.CRT&#34; publickeytoken=&#34;1fc8b3b9a1e18e3b&#34; processorarchitecture=&#34;x86&#34; version=&#34;9.0.21022.8&#34; type=&#34;win32&#34;&#62;&#60;/assemblyidentity&#62; &#60;file name=&#34;msvcr90.dll&#34;&#62;&#60;/file&#62; &#60;file name=&#34;msvcp90.dll&#34;&#62;&#60;/file&#62; &#60;/assembly&#62; 5. 找到Windows\WinSxS目录下的x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.21022.8_&#8230;目录，复制其中的msvcr90.dll和msvcp90.dll到bin目录 Visual C++ 2010制作要领 VC 2010还在Beta阶段，不过据说已经决定不用SxS，直接用DLL发布了，所以制作简单点。 1-3和2008类似，复制bin, include, [...]]]></description>
			<content:encoded><![CDATA[<p>VC的IDE开发环境很好，但太大了，经常是2005/2008/2010装一大堆，占用几十G的空间。用惯了Linux的命令行方式，觉得小巧精致。于是想把VC的基本命令提取出来，也做一个绿色版本。</p>
<p>保留基本的编译命令，cl、lib、link、ml之类的。编译工程只能用nmake了。vcproj工程文件怎么办？用scons重写一个吧。(其实命令行也有个vcbuild)。</p>
<p>制作绿色版之前，首先要安装一个VC，再把其中用到的文件提取出来。或者直接快进到后面找下载链接。</p>
<h4></h4>
<p>  <span id="more-448"></span><br />
<h4>Visual C++ 2008制作要领</h4>
<p>VC 2008的最大问题是Visual Studio采用Side-by-Side方式发布，不能简单的把依赖的DLL着全就行了。</p>
<p>1. 复制C:\Program Files\Microsoft Visual Studio&#160; 9.0\VC\bin及其子目录1033，到新的vc9\bin目录</p>
<p>2. 在复制VC目录下的lib和include目录，到新的vc9目录下</p>
<p>3. 复制C:\Program Files\Microsoft Visual Studio 2008\Common7\IDE目录下的：msobj80.dll，mspdb80.dll, mspdbcore.dll, mspdbsrv.exe到vc9\bin</p>
<p>4. 在vc\bin生成manifest文件，名为Micrisoft.VC90.CRT.manifest，内容如下</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;2.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span> <span style="color: #000066;">standalone</span>=<span style="color: #ff0000;">&quot;yes&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;assembly</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;urn:schemas-microsoft-com:asm.v1&quot;</span> <span style="color: #000066;">manifestversion</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;noinheritable<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/noinheritable<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;assemblyidentity</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Microsoft.VC90.CRT&quot;</span> <span style="color: #000066;">publickeytoken</span>=<span style="color: #ff0000;">&quot;1fc8b3b9a1e18e3b&quot;</span> <span style="color: #000066;">processorarchitecture</span>=<span style="color: #ff0000;">&quot;x86&quot;</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;9.0.21022.8&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;win32&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/assemblyidentity<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;file</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;msvcr90.dll&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/file<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;file</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;msvcp90.dll&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/file<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/assembly<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>5. 找到Windows\WinSxS目录下的x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.21022.8_&#8230;目录，复制其中的msvcr90.dll和msvcp90.dll到bin目录</p>
<h4>Visual C++ 2010制作要领</h4>
<p>VC 2010还在Beta阶段，不过据说已经决定不用SxS，直接用DLL发布了，所以制作简单点。</p>
<p>1-3和2008类似，复制bin, include, lib，复制Common7\IDE目录下的几个dll和exe</p>
<p>4. 到Windows\System32目录下找msvcr100.dll, msvcp100.dll，复制到bin</p>
<h4>Windows SDK</h4>
<p>VC的lib和include里面不带Windows的头文件和库，所以还需要把Windows SDK摘取出来。Windows SDK在安装的时候一般装在C:\Program Files\Microsoft SDKs\Windows\XX目录下，同样把其中的bin, lib, include目录复制出来，到一个新目录，比如win6sdk。</p>
<h4></h4>
<h4>环境设置</h4>
<p>影响C编译器的环境变量就三个，INCLUDE、LIB和PATH。设置好就可以编译了。假定上面我把VC 2008和Windows SDK分别复制到了vc9和win6sdk目录下，在与这两个目录的上级目录中，创建一个BAT脚本，假设叫vc9.bat，包含下面内容：</p>

<div class="wp_syntax"><div class="code"><pre class="bat" style="font-family:monospace;">@echo off
echo Setting environment Visual C++ 2010
&nbsp;
set VCINSTALLDIR=%~dp0vc9
set WindowsSdkDir=%~dp0win6sdk
&nbsp;
set INCLUDE=%WindowsSdkDir%\include;%VCINSTALLDIR%\include
set LIB=%WindowsSdkDir%\lib;%VCINSTALLDIR%\lib
set PATH=%FrameworkDir%\%FrameworkVersion%;%WindowsSdkDir%\bin;%VCINSTALLDIR%\bin;%PATH%</pre></div></div>

<p>再创建一个BAT脚本，叫start-vc9.bat，包含下面一行：</p>

<div class="wp_syntax"><div class="code"><pre class="bat" style="font-family:monospace;">start cmd /K %~dp0vc10.bat</pre></div></div>

<p>在Windows资源管理器中双击start-vc9.bat就可以配置好环境变量，进入VC 2008的编译环境了。</p>
<h4>下载</h4>
<p>1. vc10.rar 21M 2010的命令行工具和include/lib打包 <a href="http://www.uploadground.com/files/EPIKIHXP/vc10.rar" target="_blank">下载</a></p>
<p>需要和3解压到到一起用。双击start-vc10.bat打开一个命令行窗口，就可以用cl, nmake, link等命令了。VC需要的基本环境变量会自动设置。</p>
<p>2. vc9.rar 15M 2008的命令行工具和include/lib打包 <a href="http://www.uploadground.com/files/PY34KVNT/vc9.rar" target="_blank">下载</a></p>
<p>需要和3解压到一起用。双击start-vc9.bat打开命令行窗口，VC需要的环境变量会自动设置。</p>
<p>3. win7.rar 16M Windows 7.0 SDK的include/lib打包 <a href="http://www.uploadground.com/files/1FX250AB/win7.rar" target="_blank">下载</a></p>
<p>注意：命令行编译环境没有包含Debug版的CRT，所有的MFC、ATL的DLL。所以可能存在编译好的程序缺少DLL不能运行的问题。对于2008，可以下载一个VC相关SxS打包。缺DLL就到里面找(参见我的<a href="/2009/11/09/side-by-side-assembly/" target="_blank">Side-by-Side笔记</a>)。对于2010，由于已经废弃了SxS的发布方式，可以直接到网上下载缺的DLL。</p>
]]></content:encoded>
			<wfw:commentRss>http://dipplum.com/2009/11/13/visualc-compiler-portable/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Side-by-Side Assembly相关</title>
		<link>http://dipplum.com/2009/11/09/side-by-side-assembly/</link>
		<comments>http://dipplum.com/2009/11/09/side-by-side-assembly/#comments</comments>
		<pubDate>Mon, 09 Nov 2009 04:10:11 +0000</pubDate>
		<dc:creator>li</dc:creator>
				<category><![CDATA[Windows]]></category>
		<category><![CDATA[side-by-side]]></category>
		<category><![CDATA[sxs]]></category>
		<category><![CDATA[win32]]></category>

		<guid isPermaLink="false">http://dipplum.com/2009/11/09/side-by-side-assembly/</guid>
		<description><![CDATA[什么是Side-by-Side Assembly？ Side-by-Side Assembly（建称SxS）是微软在Visual Studio 2005（Windows 2000？）中引入的技术，用来解决Windows平台上的DLL Hell问题。DLL Hell的介绍可以看Wikipedia的文章。简单的说，DLL Hell窘境包括了Windows应用程序依赖的DLL带来的若干问题，包括同名DLL、DLL升级、DLL载入顺序等等。 Side-by-Side Assembly按照我的理解，是一种特殊的DLL，按照Side-by-Side Assembly的要求开发的，并用XML格式的manifest和policy文件描述的。所有的系统Side-by-Side Assembly都安装在Windows目录下的WinSxS子目录里，有一堆的目录、DLL和XML文件。 Side-by-Side Assembly的使用参见MSDN。但MSDN有把简单问题复杂化的毛病，原理讲的很多，实际例子举的很少，不看也罢。 使用Side-by-Side Assembly包括两个方面，一方面是自己开发的应用程序和DLL如何依赖Side-by-Side Assembly，另一方面是如何开发自己的Side-by-Side Assembly。如果只关心第一个方面，问题要简单的多。不需要关心第二个方面的原因如下。 Visual Studio 2010要取消对Side-by-Side Assembly的默认支持？ 消息来源于微软的博客，根据文章介绍，2010要改变对应用默认采用的SxS发布方式，回到类似2003的方式，同时支持对CRT的静态和动态联编，对DLL的搜索顺序也是常用的：先搜索应用程序目录，然后System32，然后PATH。 当然SxS还是有的，应该只是Visual Studio不再在开发应用时默认采用。 应用如何依赖Side-by-Side Assembly cl.exe在链接生成EXE的时候，会同时生成一个同名的manifest文件。该文件是XML格式的，描述了EXE对SxS的依赖。下面是一个manifest的例子： &#60;?xml version=&#34;2.0&#34; encoding=&#34;UTF-8&#34; standalone=&#34;yes&#34;?&#62; &#60;assembly xmlns=&#34;urn:schemas-microsoft-com:asm.v1&#34; manifestversion=&#34;1.0&#34;&#62; &#60;trustinfo xmlns=&#34;urn:schemas-microsoft-com:asm.v3&#34;&#62; &#60;security&#62; &#60;requestedprivileges&#62; &#60;requestedexecutionlevel uiaccess=&#34;false&#34; level=&#34;asInvoker&#34;&#62;&#60;/requestedexecutionlevel&#62; &#60;/requestedprivileges&#62; &#60;/security&#62; &#60;/trustinfo&#62; &#60;dependency&#62; &#60;dependentassembly&#62; &#60;assemblyidentity name=&#34;Microsoft.VC90.CRT&#34; publickeytoken=&#34;1fc8b3b9a1e18e3b&#34; processorarchitecture=&#34;x86&#34; version=&#34;9.0.21022.8&#34; type=&#34;win32&#34;&#62;&#60;/assemblyidentity&#62; [...]]]></description>
			<content:encoded><![CDATA[<h4>什么是Side-by-Side Assembly？</h4>
<p>Side-by-Side Assembly（建称SxS）是微软在Visual Studio 2005（Windows 2000？）中引入的技术，用来解决Windows平台上的DLL Hell问题。DLL Hell的介绍可以看<a href="http://en.wikipedia.org/wiki/DLL_hell" target="_blank">Wikipedia的文章</a>。简单的说，DLL Hell窘境包括了Windows应用程序依赖的DLL带来的若干问题，包括同名DLL、DLL升级、DLL载入顺序等等。</p>
<p>Side-by-Side Assembly按照我的理解，是一种特殊的DLL，按照Side-by-Side Assembly的要求开发的，并用XML格式的manifest和policy文件描述的。所有的系统Side-by-Side Assembly都安装在Windows目录下的WinSxS子目录里，有一堆的目录、DLL和XML文件。</p>
<p>Side-by-Side Assembly的使用<a href="http://msdn.microsoft.com/en-us/library/aa376307%28VS.85%29.aspx" target="_blank">参见MSDN</a>。但MSDN有把简单问题复杂化的毛病，原理讲的很多，实际例子举的很少，不看也罢。</p>
<p>使用Side-by-Side Assembly包括两个方面，一方面是自己开发的应用程序和DLL如何依赖Side-by-Side Assembly，另一方面是如何开发自己的Side-by-Side Assembly。如果只关心第一个方面，问题要简单的多。不需要关心第二个方面的原因如下。</p>
<h4></h4>
<p> <span id="more-420"></span><br />
<h4>Visual Studio 2010要取消对Side-by-Side Assembly的默认支持？</h4>
<p>消息来源于<a href="http://blogs.msdn.com/vcblog/archive/2008/10/28/visual-studio-2010-ctp-released.aspx" target="_blank">微软的博客</a>，根据文章介绍，2010要改变对应用默认采用的SxS发布方式，回到类似2003的方式，同时支持对CRT的静态和动态联编，对DLL的搜索顺序也是常用的：先搜索应用程序目录，然后System32，然后PATH。</p>
<p>当然SxS还是有的，应该只是Visual Studio不再在开发应用时默认采用。</p>
<h4>应用如何依赖Side-by-Side Assembly</h4>
<p>cl.exe在链接生成EXE的时候，会同时生成一个同名的manifest文件。该文件是XML格式的，描述了EXE对SxS的依赖。下面是一个manifest的例子：</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;2.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span> <span style="color: #000066;">standalone</span>=<span style="color: #ff0000;">&quot;yes&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;assembly</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;urn:schemas-microsoft-com:asm.v1&quot;</span> <span style="color: #000066;">manifestversion</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;trustinfo</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;urn:schemas-microsoft-com:asm.v3&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;security<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;requestedprivileges<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;requestedexecutionlevel</span> <span style="color: #000066;">uiaccess</span>=<span style="color: #ff0000;">&quot;false&quot;</span> <span style="color: #000066;">level</span>=<span style="color: #ff0000;">&quot;asInvoker&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/requestedexecutionlevel<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/requestedprivileges<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/security<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/trustinfo<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dependentassembly<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;assemblyidentity</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Microsoft.VC90.CRT&quot;</span> <span style="color: #000066;">publickeytoken</span>=<span style="color: #ff0000;">&quot;1fc8b3b9a1e18e3b&quot;</span> <span style="color: #000066;">processorarchitecture</span>=<span style="color: #ff0000;">&quot;x86&quot;</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;9.0.21022.8&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;win32&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/assemblyidentity<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dependentassembly<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/assembly<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>如果删除这个manifest文件，运行该EXE会出现类似下面的错误：</p>
<p><a href="http://dipplum.com/files/2009/11/manifesterror.png" rel="shadowbox[sbpost-420];player=img;"><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="manifest-error" border="0" alt="manifest-error" src="http://dipplum.com/files/2009/11/manifesterror_thumb.png" width="421" height="149" /></a> </p>
<p>这是因为缺少manifest文件的描述，程序不知道如何载入WinSxS目录下的DLL。所以最好把manifest文件嵌入EXE中，可以用mt.exe工具完成这一工作：</p>

<div class="wp_syntax"><div class="code"><pre class="batch" style="font-family:monospace;">mt.exe -manifest &lt;manifest-file&gt; -outputresource:&lt;exe-file&gt;;#1</pre></div></div>

<p>用IDE开发不存在这个问题，IDE会自动调用mt.exe将manifest嵌入EXE</p>
<h4>DLL如何依赖Side-by-Side Assembly</h4>
<p>同上述原因，DLL生成之后，最好也用mt.exe将manifest文件嵌入。方法与上面类似，不同之处在资源ID应该是2而不是1，其中的区别参见<a href="http://blogs.msdn.com/junfeng/archive/2007/06/26/rt-manifest-resource-and-isolation-aware-enabled.aspx" target="_blank">【1】</a><a href="http://blogs.msdn.com/zakramer/archive/2006/05/22/603558.aspx" target="_blank">【2】</a>，硬记也行，没什么道理。</p>

<div class="wp_syntax"><div class="code"><pre class="batch" style="font-family:monospace;">mt.exe -manifest &lt;manifest-file&gt; -outputresource:&lt;dll-file&gt;;#2</pre></div></div>

<p>用IDE开发也不存在这个问题，IDE会自动调用mt.exe将manifest嵌入DLL</p>
<h4>如何绕过Side-by-Side Assembly？</h4>
<p>Side-by-Side Assembly带来了很多不便，比如说，依赖SxS MSVCR90.dll的程序在没有安装VC redistributable的系统中不能运行，像是WinPE环境。因此最好有一种绕过SxS的方法，将SxS的Assembly和EXE放在一个目录下，避免依赖系统WinSxS目录下的Assembly。</p>
<p>1. 首先，我们需要manifest文件，如果手头没有EXE和DLL的manifest文件，可以用mt.exe工具从EXE和DLL中导出manifest文件</p>
<p>导出EXE的manifest</p>

<div class="wp_syntax"><div class="code"><pre class="batch" style="font-family:monospace;">mt.exe -inputresource:&lt;exe-file&gt;;#1 -out:&lt;manifest-file&gt;</pre></div></div>

<p>导出DLL的manifest</p>

<div class="wp_syntax"><div class="code"><pre class="batch" style="font-family:monospace;">mt.exe -outputresource:&lt;dll-file&gt;;#2 -out:&lt;manifest-file&gt;</pre></div></div>

<p>2. 根据manifest中的信息，创建若干新的manifest文件。新manifest文件名和EXE中依赖的Assembly名字对应，例如按照前面的manifest例子，应该对应创建一个Microsoft.VC90.CRT.manifest，内容格式如下：</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;2.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span> <span style="color: #000066;">standalone</span>=<span style="color: #ff0000;">&quot;yes&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;assembly</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;urn:schemas-microsoft-com:asm.v1&quot;</span> <span style="color: #000066;">manifestversion</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;noinheritable<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/noinheritable<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;assemblyidentity</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Microsoft.VC90.CRT&quot;</span> <span style="color: #000066;">publickeytoken</span>=<span style="color: #ff0000;">&quot;1fc8b3b9a1e18e3b&quot;</span> <span style="color: #000066;">processorarchitecture</span>=<span style="color: #ff0000;">&quot;x86&quot;</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;9.0.21022.8&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;win32&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/assemblyidentity<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;file</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;msvcr90.dll&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/file<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;file</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;msvcp90.dll&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/file<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/assembly<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>其中assemblyIdentity和原EXE的内容要完全一样。</p>
<p>3. 根据manifest文件中的assemblyIdentity信息，到系统的WinSxS目录下的子目录里找DLL，子目录名的格式是&lt;processorArchchitecture&gt;-&lt;name&gt;-&lt;publicKeyToken&gt;-&lt;version&gt;-none-xxx。把子目录下的DLL拷贝到EXE所在的目录下。把DLL的名字写入新manifest的file标签下。</p>
<p>至此，已经把Assembly放到EXE所在目录下，EXE也不再依赖系统WinSxS目录下的Assembly了。</p>
<h4>VC 2005和VC 2008相关的SxS打包</h4>
<p>我把自己系统中WinSxS目录下所有x86_micosoft.vc开头的目录全部拷贝出来，打了个包，以备不时之需。（<a href="http://www.uploadground.com/files/07MZXBUU/Microsoft.VCXX.SxS.zip" target="_blank">下载链接</a>）</p>
]]></content:encoded>
			<wfw:commentRss>http://dipplum.com/2009/11/09/side-by-side-assembly/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

