<?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>简单生活 -- Kevin Yang的博客 &#187; Visual Studio</title>
	<atom:link href="http://www.imkevinyang.com/tags/visual-studio/feed" rel="self" type="application/rss+xml" />
	<link>http://www.imkevinyang.com</link>
	<description>It&#039;s all about sharing</description>
	<lastBuildDate>Sun, 05 Feb 2012 15:37:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>VS编译时自动引用Debug&#124;Release版本的dll</title>
		<link>http://www.imkevinyang.com/2011/04/vs%e7%bc%96%e8%af%91%e6%97%b6%e8%87%aa%e5%8a%a8%e5%bc%95%e7%94%a8debugrelease%e7%89%88%e6%9c%ac%e7%9a%84dll.html</link>
		<comments>http://www.imkevinyang.com/2011/04/vs%e7%bc%96%e8%af%91%e6%97%b6%e8%87%aa%e5%8a%a8%e5%bc%95%e7%94%a8debugrelease%e7%89%88%e6%9c%ac%e7%9a%84dll.html#comments</comments>
		<pubDate>Sun, 10 Apr 2011 14:13:04 +0000</pubDate>
		<dc:creator>Kevin Yang</dc:creator>
				<category><![CDATA[工具技巧]]></category>
		<category><![CDATA[Debug]]></category>
		<category><![CDATA[dll]]></category>
		<category><![CDATA[Release]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[发布]]></category>
		<category><![CDATA[类库引用]]></category>
		<category><![CDATA[编译选项]]></category>

		<guid isPermaLink="false">http://www.imkevinyang.com/2011/04/vs%e7%bc%96%e8%af%91%e6%97%b6%e8%87%aa%e5%8a%a8%e5%bc%95%e7%94%a8debugrelease%e7%89%88%e6%9c%ac%e7%9a%84dll.html</guid>
		<description><![CDATA[<p>公司一些早期的项目，把所有工程都放到一个解决方案下了，导致整个解决方案编译很慢，而且也不便于类库的复用和维护。因此我们决定把工程按照功能划分到不同的解决方案里头，然后定期发布dll到TFS配置库上固定的TeamProject下面，以后应用程序引用时就不添加工程，而是采用添加dll的方式。但是现在遇到&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>公司一些早期的项目，把所有工程都放到一个解决方案下了，导致整个解决方案编译很慢，而且也不便于类库的复用和维护。因此我们决定把工程按照功能划分到不同的解决方案里头，然后定期发布dll到TFS配置库上固定的TeamProject下面，以后应用程序引用时就不添加工程，而是采用添加dll的方式。但是现在遇到一个问题，发布dll一般会发布Debug和Release两个版本，那么应用程序应该引用哪个版本呢？</p>
<p>理想情况下，开发测试的时候应该使用Debug版本，这样抛异常的时候调试很方便。正式部署到生产环境的时候可以使用Release版本，这样性能好一些。但是添加dll的时候VS只允许选择一个版本。</p>
<p>我们知道，VS支持把工程不同的编译选项保存到不同的配置中，编译时根据当前使用的配置来决定采用什么样的编译选项。默认会新建Debug和Release这两个配置。开发时我们一般选Debug配置，发布时一般选择Release。</p>
<p><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="Visual studio Configuration manager" border="0" alt="Visual studio Configuration manager" src="http://www.imkevinyang.com/wp-content/uploads/2011/04/image.png" width="562" height="191" /></p>
<p>如果添加dll时也能根据当前配置引用不同路径的dll，那就好了。在stackoverflow上搜到了相关的信息，说可以修改csproj工程文件，使用VS宏变量来指定dll路径。用记事本打开研究了一番倒也挺简单的.找到引用类库的地方：</p>
<p>&lt;ItemGroup&gt;   <br />&#160; &lt;Reference Include=&quot;ClassLibrary1,Version=1.0.0.0,Culture=neutral,processorArchitecture=MSIL&quot;&gt;    <br />&#160;&#160;&#160; &lt;SpecificVersion&gt;False&lt;/SpecificVersion&gt;    <br />&#160;&#160;&#160; &lt;HintPath&gt;<font color="#000000"><strong>Lib\Debug\ClassLibrary1.dll</strong></font>&lt;/HintPath&gt;    <br />&#160; &lt;/Reference&gt;</p>
<p>只需要改成：</p>
<p>&lt;ItemGroup&gt;   <br />&#160;&#160;&#160; &lt;Reference Include=&quot;ClassLibrary1, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL&quot;&gt;    <br />&#160;&#160;&#160;&#160;&#160; &lt;SpecificVersion&gt;False&lt;/SpecificVersion&gt;    <br />&#160;&#160;&#160;&#160;&#160; &lt;HintPath&gt;<strong>Lib\<font color="#ff0000">$(Configuration)</font><font color="#000000">\</font>ClassLibrary1.dll</strong>&lt;/HintPath&gt;    <br />&#160;&#160;&#160; &lt;/Reference&gt;</p>
<p>这样编译时VS就能根据当前配置到Debug或者Release文件夹下寻找相应的dll了。</p>
<p>不过这样一来，以后添加dll的时候就有点麻烦了，每次都要手工编辑csproj文件。同事吴突发奇想，<strong>能不能在发布的时候再建一个名为“$(Configuration)”的文件夹，以后直接引用这个文件夹下的dll即可，都不需要修改csproj文件了</strong>。我的第一个反应是VS应该会对这样的路径做转义之类的，因为和内置变量名冲突了。但本着“不确定的事情要通过实验去验证”的精神，我做了这个实验，发现居然可以！VS才不管你路径包含什么字符串呢。</p>
<p>最后的结论，发布dll时，需要同时发布到以下三个文件夹：</p>
<ul>
<li>$(Configuration)\MyLibrary.dll</li>
<li>Debug\MyLibrary.dll</li>
<li>Release\MyLibrary.dll</li>
</ul>
<p>其中$(Configuration)文件夹下的dll无所谓哪个版本了，这个纯粹只是为了骗过Visual Studio的而已，编译时根本不会用到。添加dll引用的时候，直接引用$(Configuration)\MyLibrary.dll即可。</p>
<p>希望此文对你有帮助。</p>
<p>== <a style="font-family: comic sans ms; color: black; font-weight: bold; text-decoration: none" title="VS编译时自动引用Debug|Release版本的dll" href="http://www.imkevinyang.com/2011/04/VS%e7%bc%96%e8%af%91%e6%97%b6%e8%87%aa%e5%8a%a8%e5%bc%95%e7%94%a8Debug|Release%e7%89%88%e6%9c%ac%e7%9a%84dll.html" target="_self">Kevin Yang</a> == </p>

	标签：<a href="http://www.imkevinyang.com/tags/debug" title="Debug" rel="tag">Debug</a>, <a href="http://www.imkevinyang.com/tags/dll" title="dll" rel="tag">dll</a>, <a href="http://www.imkevinyang.com/tags/release" title="Release" rel="tag">Release</a>, <a href="http://www.imkevinyang.com/tags/visual-studio" title="Visual Studio" rel="tag">Visual Studio</a>, <a href="http://www.imkevinyang.com/tags/%e5%8f%91%e5%b8%83" title="发布" rel="tag">发布</a>, <a href="http://www.imkevinyang.com/categories/techarticles/toolskills-techarticles" title="工具技巧" rel="tag">工具技巧</a>, <a href="http://www.imkevinyang.com/tags/%e7%b1%bb%e5%ba%93%e5%bc%95%e7%94%a8" title="类库引用" rel="tag">类库引用</a>, <a href="http://www.imkevinyang.com/tags/%e7%bc%96%e8%af%91%e9%80%89%e9%a1%b9" title="编译选项" rel="tag">编译选项</a><br />

	<h4 style="background-color:#3B3B3B;border-bottom:2px groove gray;color:#F2F2F2;margin-top:20px;padding:6px 6px 6px 15px;margin:20px 0px 0px 0px">你可能对下面的文章感兴趣</h4>
	<ul class="st-related-posts">
	<li><a href="http://www.imkevinyang.com/2009/09/visual-assist%e4%bb%a3%e7%a0%81%e6%8f%90%e7%a4%ba%e4%bd%bf%e7%94%a8%e7%9a%84%e5%ad%97%e7%ac%a6%e4%b8%b2%e6%a8%a1%e7%b3%8a%e5%8c%b9%e9%85%8d%e7%ae%97%e6%b3%95.html" title="Visual Assist代码提示使用的字符串模糊匹配算法 (2009/09/28)">Visual Assist代码提示使用的字符串模糊匹配算法</a> </li>
	<li><a href="http://www.imkevinyang.com/2010/09/visual-studio-2010%e9%87%8d%e5%91%bd%e5%90%8d%e9%87%8d%e6%9e%84%e6%97%b6%e5%87%ba%e7%8e%b0%e7%9a%84%e9%97%ae%e9%a2%98.html" title="Visual Studio 2010重命名重构时出现的问题 (2010/09/29)">Visual Studio 2010重命名重构时出现的问题</a> </li>
	<li><a href="http://www.imkevinyang.com/2009/09/visual-studio%e5%b0%8f%e8%b4%b4%e5%a3%ab%e5%8a%a0%e4%ba%86try-catch%e4%b9%9f%e8%83%bd%e8%87%aa%e5%8a%a8%e5%ae%9a%e4%bd%8d%e5%88%b0%e5%bc%82%e5%b8%b8%e4%bb%a3%e7%a0%81.html" title="Visual Studio小贴士&mdash;&mdash;加了Try-Catch也能自动定位到异常代码 (2009/09/18)">Visual Studio小贴士&mdash;&mdash;加了Try-Catch也能自动定位到异常代码</a> </li>
	<li><a href="http://www.imkevinyang.com/2009/05/visual-studio%e7%bb%9f%e8%ae%a1%e6%9c%89%e6%95%88%e4%bb%a3%e7%a0%81%e8%a1%8c%e6%95%b0.html" title="Visual Studio统计有效代码行数 (2009/05/22)">Visual Studio统计有效代码行数</a> </li>
	<li><a href="http://www.imkevinyang.com/2010/07/visual-studio%e7%bc%96%e8%be%91%e5%99%a8%e4%b8%80%e6%ac%a1%e7%bc%a9%e8%bf%9b%e5%8f%8d%e7%bc%a9%e8%bf%9b4%e4%b8%aa%e7%a9%ba%e6%a0%bc.html" title="Visual Studio编辑器一次缩进/反缩进4个空格 (2010/07/04)">Visual Studio编辑器一次缩进/反缩进4个空格</a> </li>
	<li><a href="http://www.imkevinyang.com/2010/05/vs2010%e7%9a%84ui%e8%ae%be%e8%ae%a1%e5%a4%b1%e8%af%af.html" title="VS2010的UI设计失误 (2010/05/31)">VS2010的UI设计失误</a> </li>
	<li><a href="http://www.imkevinyang.com/2009/09/%e8%a7%a3%e5%86%b3silverlight%e6%97%a0%e6%b3%95%e8%b0%83%e8%af%95%e7%9a%84%e9%97%ae%e9%a2%98.html" title="解决Silverlight无法调试的问题 (2009/09/01)">解决Silverlight无法调试的问题</a> </li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://www.imkevinyang.com/2011/04/vs%e7%bc%96%e8%af%91%e6%97%b6%e8%87%aa%e5%8a%a8%e5%bc%95%e7%94%a8debugrelease%e7%89%88%e6%9c%ac%e7%9a%84dll.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Visual Studio 2010重命名重构时出现的问题</title>
		<link>http://www.imkevinyang.com/2010/09/visual-studio-2010%e9%87%8d%e5%91%bd%e5%90%8d%e9%87%8d%e6%9e%84%e6%97%b6%e5%87%ba%e7%8e%b0%e7%9a%84%e9%97%ae%e9%a2%98.html</link>
		<comments>http://www.imkevinyang.com/2010/09/visual-studio-2010%e9%87%8d%e5%91%bd%e5%90%8d%e9%87%8d%e6%9e%84%e6%97%b6%e5%87%ba%e7%8e%b0%e7%9a%84%e9%97%ae%e9%a2%98.html#comments</comments>
		<pubDate>Wed, 29 Sep 2010 08:00:00 +0000</pubDate>
		<dc:creator>Kevin Yang</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[2010]]></category>
		<category><![CDATA[Bug]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[重构]]></category>

		<guid isPermaLink="false">http://www.imkevinyang.com/2010/09/visual-studio-2010%e9%87%8d%e5%91%bd%e5%90%8d%e9%87%8d%e6%9e%84%e6%97%b6%e5%87%ba%e7%8e%b0%e7%9a%84%e9%97%ae%e9%a2%98.html</guid>
		<description><![CDATA[<p>某天打开VS准备对以前命名不友好的类名进行重构的时候，弹出了下面这个框：</p>
<p></p>
<p>你要点Yes就会编译出错。</p>
<p>Google了一下发现是个Bug，打开VS，在从未打开Xaml文件的前提下，对UserControl的类名做重构的时候能够重现这个Bug。参考：<a href="http://connect.microsoft.com/VisualStudio/feedback/details/550058/the-file-could-not-be-refactored">http://connect.microsoft.com/&#8230;</a></p>]]></description>
			<content:encoded><![CDATA[<p>某天打开VS准备对以前命名不友好的类名进行重构的时候，弹出了下面这个框：</p>
<p><img style="display: inline" title="image" alt="image" src="http://www.imkevinyang.com/wp-content/uploads/2010/09/image.png" width="378" height="231" /></p>
<p>你要点Yes就会编译出错。</p>
<p>Google了一下发现是个Bug，打开VS，在从未打开Xaml文件的前提下，对UserControl的类名做重构的时候能够重现这个Bug。参考：<a href="http://connect.microsoft.com/VisualStudio/feedback/details/550058/the-file-could-not-be-refactored">http://connect.microsoft.com/VisualStudio/feedback/details/550058/the-file-could-not-be-refactored</a></p>
<p>临时的解决办法就是随便打开任何一个Xaml文件。</p>
<p>记录一下。</p>
<p style="text-align: right">——<a title="Visual Studio 2010重命名重构时出现的问题" href="http://www.imkevinyang.com/2010/09/Visual%20Studio%202010%e9%87%8d%e5%91%bd%e5%90%8d%e9%87%8d%e6%9e%84%e6%97%b6%e5%87%ba%e7%8e%b0%e7%9a%84%e9%97%ae%e9%a2%98.html"><em>Kevin Yang</em></a></p>

	标签：<a href="http://www.imkevinyang.com/tags/2010" title="2010" rel="tag">2010</a>, <a href="http://www.imkevinyang.com/tags/bug" title="Bug" rel="tag">Bug</a>, <a href="http://www.imkevinyang.com/categories/techarticles/silverlight" title="Silverlight" rel="tag">Silverlight</a>, <a href="http://www.imkevinyang.com/tags/visual-studio" title="Visual Studio" rel="tag">Visual Studio</a>, <a href="http://www.imkevinyang.com/tags/%e9%87%8d%e6%9e%84" title="重构" rel="tag">重构</a><br />

	<h4 style="background-color:#3B3B3B;border-bottom:2px groove gray;color:#F2F2F2;margin-top:20px;padding:6px 6px 6px 15px;margin:20px 0px 0px 0px">你可能对下面的文章感兴趣</h4>
	<ul class="st-related-posts">
	<li><a href="http://www.imkevinyang.com/2009/11/onenote-2010-beta2-%e4%bd%93%e9%aa%8c.html" title="OneNote 2010 beta2 体验 (2009/11/25)">OneNote 2010 beta2 体验</a> </li>
	<li><a href="http://www.imkevinyang.com/2009/09/visual-assist%e4%bb%a3%e7%a0%81%e6%8f%90%e7%a4%ba%e4%bd%bf%e7%94%a8%e7%9a%84%e5%ad%97%e7%ac%a6%e4%b8%b2%e6%a8%a1%e7%b3%8a%e5%8c%b9%e9%85%8d%e7%ae%97%e6%b3%95.html" title="Visual Assist代码提示使用的字符串模糊匹配算法 (2009/09/28)">Visual Assist代码提示使用的字符串模糊匹配算法</a> </li>
	<li><a href="http://www.imkevinyang.com/2009/09/visual-studio%e5%b0%8f%e8%b4%b4%e5%a3%ab%e5%8a%a0%e4%ba%86try-catch%e4%b9%9f%e8%83%bd%e8%87%aa%e5%8a%a8%e5%ae%9a%e4%bd%8d%e5%88%b0%e5%bc%82%e5%b8%b8%e4%bb%a3%e7%a0%81.html" title="Visual Studio小贴士&mdash;&mdash;加了Try-Catch也能自动定位到异常代码 (2009/09/18)">Visual Studio小贴士&mdash;&mdash;加了Try-Catch也能自动定位到异常代码</a> </li>
	<li><a href="http://www.imkevinyang.com/2009/05/visual-studio%e7%bb%9f%e8%ae%a1%e6%9c%89%e6%95%88%e4%bb%a3%e7%a0%81%e8%a1%8c%e6%95%b0.html" title="Visual Studio统计有效代码行数 (2009/05/22)">Visual Studio统计有效代码行数</a> </li>
	<li><a href="http://www.imkevinyang.com/2010/07/visual-studio%e7%bc%96%e8%be%91%e5%99%a8%e4%b8%80%e6%ac%a1%e7%bc%a9%e8%bf%9b%e5%8f%8d%e7%bc%a9%e8%bf%9b4%e4%b8%aa%e7%a9%ba%e6%a0%bc.html" title="Visual Studio编辑器一次缩进/反缩进4个空格 (2010/07/04)">Visual Studio编辑器一次缩进/反缩进4个空格</a> </li>
	<li><a href="http://www.imkevinyang.com/2010/05/vs2010%e7%9a%84ui%e8%ae%be%e8%ae%a1%e5%a4%b1%e8%af%af.html" title="VS2010的UI设计失误 (2010/05/31)">VS2010的UI设计失误</a> </li>
	<li><a href="http://www.imkevinyang.com/2011/04/vs%e7%bc%96%e8%af%91%e6%97%b6%e8%87%aa%e5%8a%a8%e5%bc%95%e7%94%a8debugrelease%e7%89%88%e6%9c%ac%e7%9a%84dll.html" title="VS编译时自动引用Debug|Release版本的dll (2011/04/10)">VS编译时自动引用Debug|Release版本的dll</a> </li>
	<li><a href="http://www.imkevinyang.com/2011/06/%e5%8d%87%e7%ba%a7tfs-2010%e4%b9%8b%e5%90%8e%e4%bf%ae%e5%a4%8d%e5%8e%9f%e6%9c%89%e5%b7%a5%e4%bd%9c%e5%8c%ba.html" title="升级TFS 2010之后修复原有工作区 (2011/06/17)">升级TFS 2010之后修复原有工作区</a> </li>
	<li><a href="http://www.imkevinyang.com/2010/02/%e6%88%91%e7%9a%842010.html" title="我的2010 (2010/02/14)">我的2010</a> </li>
	<li><a href="http://www.imkevinyang.com/2009/09/%e8%a7%a3%e5%86%b3silverlight%e6%97%a0%e6%b3%95%e8%b0%83%e8%af%95%e7%9a%84%e9%97%ae%e9%a2%98.html" title="解决Silverlight无法调试的问题 (2009/09/01)">解决Silverlight无法调试的问题</a> </li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://www.imkevinyang.com/2010/09/visual-studio-2010%e9%87%8d%e5%91%bd%e5%90%8d%e9%87%8d%e6%9e%84%e6%97%b6%e5%87%ba%e7%8e%b0%e7%9a%84%e9%97%ae%e9%a2%98.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Visual Studio编辑器一次缩进/反缩进4个空格</title>
		<link>http://www.imkevinyang.com/2010/07/visual-studio%e7%bc%96%e8%be%91%e5%99%a8%e4%b8%80%e6%ac%a1%e7%bc%a9%e8%bf%9b%e5%8f%8d%e7%bc%a9%e8%bf%9b4%e4%b8%aa%e7%a9%ba%e6%a0%bc.html</link>
		<comments>http://www.imkevinyang.com/2010/07/visual-studio%e7%bc%96%e8%be%91%e5%99%a8%e4%b8%80%e6%ac%a1%e7%bc%a9%e8%bf%9b%e5%8f%8d%e7%bc%a9%e8%bf%9b4%e4%b8%aa%e7%a9%ba%e6%a0%bc.html#comments</comments>
		<pubDate>Sun, 04 Jul 2010 02:00:00 +0000</pubDate>
		<dc:creator>Kevin Yang</dc:creator>
				<category><![CDATA[工具技巧]]></category>
		<category><![CDATA[IDE]]></category>
		<category><![CDATA[Tab]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[空格]]></category>
		<category><![CDATA[缩进]]></category>

		<guid isPermaLink="false">http://www.imkevinyang.com/2010/07/visual-studio%e7%bc%96%e8%be%91%e5%99%a8%e4%b8%80%e6%ac%a1%e7%bc%a9%e8%bf%9b%e5%8f%8d%e7%bc%a9%e8%bf%9b4%e4%b8%aa%e7%a9%ba%e6%a0%bc.html</guid>
		<description><![CDATA[<p>在代码中使用Tab作为缩进并不是一个好的习惯，因为Tab并不是一个打印字符，而是一个控制字符，也就是说它在不同文本编辑器中显示的宽度不一定是相同的，因而显示效果容易产生不一致。而空格则具有很好的适应性，因为它就是一个普通字符，因此和其他字符一样受到相同的影响，显示效果会趋于一致。</p>
<p>那些使用Tab作为缩&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>在代码中使用Tab作为缩进并不是一个好的习惯，因为Tab并不是一个打印字符，而是一个控制字符，也就是说它在不同文本编辑器中显示的宽度不一定是相同的，因而显示效果容易产生不一致。而空格则具有很好的适应性，因为它就是一个普通字符，因此和其他字符一样受到相同的影响，显示效果会趋于一致。</p>
<p>那些使用Tab作为缩进的人通常是因为用Tab做缩进的话，可以一次删除一个缩进单位，非常方便。而如果按照一个Tab对应4个空格来转换的话，要删除一个缩进单位则需要删除4个空格，相对不便。</p>
<p>实际上，现在很多文本编辑器包括Visual Studio对Tab和空格的转换都有很好的支持，如果你设置了坚持使用空格，那么通过<strong>快捷键Tab和Shift+Tab可以实现一次插入或者删除4个空格</strong>，和使用Tab做缩进的效果是一样的。</p>
<p>这下你使用空格做缩进就不会感到不便了。</p>
<p style="text-align: right;">——<a title="Visual Studio编辑器一次缩进/反缩进4个空格" href="http://www.imkevinyang.com/2010/07/visual-studio%E7%BC%96%E8%BE%91%E5%99%A8%E4%B8%80%E6%AC%A1%E7%BC%A9%E8%BF%9B%E5%8F%8D%E7%BC%A9%E8%BF%9B4%E4%B8%AA%E7%A9%BA%E6%A0%BC.html" target="_self"><em>Kevin Yang</em></a></p>

	标签：<a href="http://www.imkevinyang.com/tags/ide" title="IDE" rel="tag">IDE</a>, <a href="http://www.imkevinyang.com/tags/tab" title="Tab" rel="tag">Tab</a>, <a href="http://www.imkevinyang.com/tags/visual-studio" title="Visual Studio" rel="tag">Visual Studio</a>, <a href="http://www.imkevinyang.com/categories/techarticles/toolskills-techarticles" title="工具技巧" rel="tag">工具技巧</a>, <a href="http://www.imkevinyang.com/tags/%e7%a9%ba%e6%a0%bc" title="空格" rel="tag">空格</a>, <a href="http://www.imkevinyang.com/tags/%e7%bc%a9%e8%bf%9b" title="缩进" rel="tag">缩进</a><br />

	<h4 style="background-color:#3B3B3B;border-bottom:2px groove gray;color:#F2F2F2;margin-top:20px;padding:6px 6px 6px 15px;margin:20px 0px 0px 0px">你可能对下面的文章感兴趣</h4>
	<ul class="st-related-posts">
	<li><a href="http://www.imkevinyang.com/2009/09/visual-assist%e4%bb%a3%e7%a0%81%e6%8f%90%e7%a4%ba%e4%bd%bf%e7%94%a8%e7%9a%84%e5%ad%97%e7%ac%a6%e4%b8%b2%e6%a8%a1%e7%b3%8a%e5%8c%b9%e9%85%8d%e7%ae%97%e6%b3%95.html" title="Visual Assist代码提示使用的字符串模糊匹配算法 (2009/09/28)">Visual Assist代码提示使用的字符串模糊匹配算法</a> </li>
	<li><a href="http://www.imkevinyang.com/2010/09/visual-studio-2010%e9%87%8d%e5%91%bd%e5%90%8d%e9%87%8d%e6%9e%84%e6%97%b6%e5%87%ba%e7%8e%b0%e7%9a%84%e9%97%ae%e9%a2%98.html" title="Visual Studio 2010重命名重构时出现的问题 (2010/09/29)">Visual Studio 2010重命名重构时出现的问题</a> </li>
	<li><a href="http://www.imkevinyang.com/2009/09/visual-studio%e5%b0%8f%e8%b4%b4%e5%a3%ab%e5%8a%a0%e4%ba%86try-catch%e4%b9%9f%e8%83%bd%e8%87%aa%e5%8a%a8%e5%ae%9a%e4%bd%8d%e5%88%b0%e5%bc%82%e5%b8%b8%e4%bb%a3%e7%a0%81.html" title="Visual Studio小贴士&mdash;&mdash;加了Try-Catch也能自动定位到异常代码 (2009/09/18)">Visual Studio小贴士&mdash;&mdash;加了Try-Catch也能自动定位到异常代码</a> </li>
	<li><a href="http://www.imkevinyang.com/2009/05/visual-studio%e7%bb%9f%e8%ae%a1%e6%9c%89%e6%95%88%e4%bb%a3%e7%a0%81%e8%a1%8c%e6%95%b0.html" title="Visual Studio统计有效代码行数 (2009/05/22)">Visual Studio统计有效代码行数</a> </li>
	<li><a href="http://www.imkevinyang.com/2010/05/vs2010%e7%9a%84ui%e8%ae%be%e8%ae%a1%e5%a4%b1%e8%af%af.html" title="VS2010的UI设计失误 (2010/05/31)">VS2010的UI设计失误</a> </li>
	<li><a href="http://www.imkevinyang.com/2011/04/vs%e7%bc%96%e8%af%91%e6%97%b6%e8%87%aa%e5%8a%a8%e5%bc%95%e7%94%a8debugrelease%e7%89%88%e6%9c%ac%e7%9a%84dll.html" title="VS编译时自动引用Debug|Release版本的dll (2011/04/10)">VS编译时自动引用Debug|Release版本的dll</a> </li>
	<li><a href="http://www.imkevinyang.com/2009/10/%e5%85%a8%e5%8d%8a%e8%a7%92%e7%a9%ba%e6%a0%bc%e5%af%bc%e8%87%b4%e7%9a%84analysis-service%e5%a4%84%e7%90%86%e9%94%99%e8%af%af.html" title="全半角空格导致的Analysis Services处理错误 (2009/10/09)">全半角空格导致的Analysis Services处理错误</a> </li>
	<li><a href="http://www.imkevinyang.com/2009/09/%e8%a7%a3%e5%86%b3silverlight%e6%97%a0%e6%b3%95%e8%b0%83%e8%af%95%e7%9a%84%e9%97%ae%e9%a2%98.html" title="解决Silverlight无法调试的问题 (2009/09/01)">解决Silverlight无法调试的问题</a> </li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://www.imkevinyang.com/2010/07/visual-studio%e7%bc%96%e8%be%91%e5%99%a8%e4%b8%80%e6%ac%a1%e7%bc%a9%e8%bf%9b%e5%8f%8d%e7%bc%a9%e8%bf%9b4%e4%b8%aa%e7%a9%ba%e6%a0%bc.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>VS2010的UI设计失误</title>
		<link>http://www.imkevinyang.com/2010/05/vs2010%e7%9a%84ui%e8%ae%be%e8%ae%a1%e5%a4%b1%e8%af%af.html</link>
		<comments>http://www.imkevinyang.com/2010/05/vs2010%e7%9a%84ui%e8%ae%be%e8%ae%a1%e5%a4%b1%e8%af%af.html#comments</comments>
		<pubDate>Sun, 30 May 2010 17:24:18 +0000</pubDate>
		<dc:creator>Kevin Yang</dc:creator>
				<category><![CDATA[生活网事]]></category>
		<category><![CDATA[UI设计]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[VS2010]]></category>
		<category><![CDATA[右键菜单]]></category>
		<category><![CDATA[自定义工具栏]]></category>

		<guid isPermaLink="false">http://www.imkevinyang.com/2010/05/vs2010%e7%9a%84ui%e8%ae%be%e8%ae%a1%e5%a4%b1%e8%af%af.html</guid>
		<description><![CDATA[<p><font color="#ff0000">update: 有人跟我说右键菜单的问题，可以通过按住Ctrl键+滚轮来实现右键菜单的滚动。但这样的设计还是让人无法接受。因为当你鼠标位于菜单之上的时候，滚轮的意义应该很明确了，应该是滚动菜单的，而不是菜单底下的窗口。</font></p>
<p>升级到VS2010也有一段时间了。当初升级之前看了不少文章讲VS2010的新特性的，&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p><font color="#ff0000">update: 有人跟我说右键菜单的问题，可以通过按住Ctrl键+滚轮来实现右键菜单的滚动。但这样的设计还是让人无法接受。因为当你鼠标位于菜单之上的时候，滚轮的意义应该很明确了，应该是滚动菜单的，而不是菜单底下的窗口。</font></p>
<p>升级到VS2010也有一段时间了。当初升级之前看了不少文章讲VS2010的新特性的，确实有挺多让人兴奋的。例如智能提示支持模糊匹配了，相比以前的前向匹配更易于使用。对并行编程调试的支持更强大，允许你更方便的调试多线程程序。Silverlight UI Designer又回来了，而且这次回来变漂亮了。我觉得完全就是按照WinForm的方式设计的。相比Blend有优势也有劣势，至少速度和响应上比Blend快了很多。</p>
<p>但是VS2010有一点让我觉得特别不爽的，就是界面采用了WPF技术重新实现，但是又没有完全继承以往的优良传统。其实Visual Studio这个IDE在2008版本的时候已经非常易用了。WPF版的界面你第一次看起来和VS2008没太多不同，只是底色从原来的灰色调变成了灰蓝色调。但是实际使用起来发现有些细节让人用起来非常不爽。</p>
<p>一个最最让人接受不了的是右键菜单的设计。</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="VS资源管理器右键菜单" border="0" alt="VS资源管理器右键菜单" src="http://www.imkevinyang.com/wp-content/uploads/2010/05/image24.png" width="181" height="239" /> </p>
<p>当菜单项稍微多了一些的时候（实际上此时菜单的长度还没有占据整个屏幕，大约只有一半左右），菜单上下会多了对箭头。当你鼠标移到箭头上，菜单就会自动滚动。</p>
<p>我一开始打开右键的时候发现菜单缩短了挺不错的，原先太长，目光需要扫描那么长一段距离，不符合UI设计原则。而且我习惯性的就会使用滚轮去上下滚动菜单，也没觉得什么不方便的。但后来我把Resharper停用了之后发现，这么自然的滚轮滚动功能居然是由Resharper提供的功能，而不是VS2010原生支持的！这让我不得不怀疑，要么这是一个实现上的Bug，要么产品经理是个根本不用VS的家伙。</p>
<p>还有一个问题是工具栏的自定义。</p>
<p>我一般新装VS第一件事就是自定义我常用的工具栏，然后把其他不常用的工具栏给关了，这样就不用占那么地方碍眼。在VS2008中你可以先在工具栏上右键菜单中选择“自定义（Customize）”，然后你就可以很自然的把其他工具栏上的图标呀，菜单中的菜单项啊拖放到新建的工具栏上。非常容易操作。而在VS2010呢，居然给我来了这么一个模式对话框：</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.imkevinyang.com/wp-content/uploads/2010/05/image25.png" width="286" height="262" />&#160;</p>
<p>要完成我刚才的操作，我必须点击Add Command，然后从茫茫菜单项中搜寻我想要的那个功能按钮或者菜单。要关闭工具栏，以往是直接将该工具栏往下拖变成浮动工具栏，然后就点关闭X就行了，现在需要点击工具栏右键二级菜单中的Customize，然后在打开的窗口中找到Delete的按钮，删之。简单的工作被复杂化成这样子。导致我用到现在工具栏还是保持新装时的样子，实在懒得去折腾了。 </p>
</p>
</p>
<p>不知道升级到VS2010的朋友有没有类似的感觉。</p>

	标签：<a href="http://www.imkevinyang.com/tags/ui%e8%ae%be%e8%ae%a1" title="UI设计" rel="tag">UI设计</a>, <a href="http://www.imkevinyang.com/tags/visual-studio" title="Visual Studio" rel="tag">Visual Studio</a>, <a href="http://www.imkevinyang.com/tags/vs2010" title="VS2010" rel="tag">VS2010</a>, <a href="http://www.imkevinyang.com/tags/%e5%8f%b3%e9%94%ae%e8%8f%9c%e5%8d%95" title="右键菜单" rel="tag">右键菜单</a>, <a href="http://www.imkevinyang.com/categories/dailylife" title="生活网事" rel="tag">生活网事</a>, <a href="http://www.imkevinyang.com/tags/%e8%87%aa%e5%ae%9a%e4%b9%89%e5%b7%a5%e5%85%b7%e6%a0%8f" title="自定义工具栏" rel="tag">自定义工具栏</a><br />

	<h4 style="background-color:#3B3B3B;border-bottom:2px groove gray;color:#F2F2F2;margin-top:20px;padding:6px 6px 6px 15px;margin:20px 0px 0px 0px">你可能对下面的文章感兴趣</h4>
	<ul class="st-related-posts">
	<li><a href="http://www.imkevinyang.com/2009/09/visual-assist%e4%bb%a3%e7%a0%81%e6%8f%90%e7%a4%ba%e4%bd%bf%e7%94%a8%e7%9a%84%e5%ad%97%e7%ac%a6%e4%b8%b2%e6%a8%a1%e7%b3%8a%e5%8c%b9%e9%85%8d%e7%ae%97%e6%b3%95.html" title="Visual Assist代码提示使用的字符串模糊匹配算法 (2009/09/28)">Visual Assist代码提示使用的字符串模糊匹配算法</a> </li>
	<li><a href="http://www.imkevinyang.com/2010/09/visual-studio-2010%e9%87%8d%e5%91%bd%e5%90%8d%e9%87%8d%e6%9e%84%e6%97%b6%e5%87%ba%e7%8e%b0%e7%9a%84%e9%97%ae%e9%a2%98.html" title="Visual Studio 2010重命名重构时出现的问题 (2010/09/29)">Visual Studio 2010重命名重构时出现的问题</a> </li>
	<li><a href="http://www.imkevinyang.com/2009/09/visual-studio%e5%b0%8f%e8%b4%b4%e5%a3%ab%e5%8a%a0%e4%ba%86try-catch%e4%b9%9f%e8%83%bd%e8%87%aa%e5%8a%a8%e5%ae%9a%e4%bd%8d%e5%88%b0%e5%bc%82%e5%b8%b8%e4%bb%a3%e7%a0%81.html" title="Visual Studio小贴士&mdash;&mdash;加了Try-Catch也能自动定位到异常代码 (2009/09/18)">Visual Studio小贴士&mdash;&mdash;加了Try-Catch也能自动定位到异常代码</a> </li>
	<li><a href="http://www.imkevinyang.com/2009/05/visual-studio%e7%bb%9f%e8%ae%a1%e6%9c%89%e6%95%88%e4%bb%a3%e7%a0%81%e8%a1%8c%e6%95%b0.html" title="Visual Studio统计有效代码行数 (2009/05/22)">Visual Studio统计有效代码行数</a> </li>
	<li><a href="http://www.imkevinyang.com/2010/07/visual-studio%e7%bc%96%e8%be%91%e5%99%a8%e4%b8%80%e6%ac%a1%e7%bc%a9%e8%bf%9b%e5%8f%8d%e7%bc%a9%e8%bf%9b4%e4%b8%aa%e7%a9%ba%e6%a0%bc.html" title="Visual Studio编辑器一次缩进/反缩进4个空格 (2010/07/04)">Visual Studio编辑器一次缩进/反缩进4个空格</a> </li>
	<li><a href="http://www.imkevinyang.com/2011/04/vs%e7%bc%96%e8%af%91%e6%97%b6%e8%87%aa%e5%8a%a8%e5%bc%95%e7%94%a8debugrelease%e7%89%88%e6%9c%ac%e7%9a%84dll.html" title="VS编译时自动引用Debug|Release版本的dll (2011/04/10)">VS编译时自动引用Debug|Release版本的dll</a> </li>
	<li><a href="http://www.imkevinyang.com/2009/09/web%e8%a1%a8%e5%8d%95%e8%ae%be%e8%ae%a1%e6%8c%87%e5%8d%97%ef%bc%9a%e7%9c%bc%e5%8a%a8%e8%b7%9f%e8%b8%aa%e7%a0%94%e7%a9%b6.html" title="Web表单设计指南：眼动跟踪研究 (2009/09/29)">Web表单设计指南：眼动跟踪研究</a> </li>
	<li><a href="http://www.imkevinyang.com/2009/12/win7vista%e9%ab%98%e7%ba%a7%e7%94%a8%e6%88%b7%e5%bf%85%e5%a4%87%e7%9a%84%e5%8f%b3%e9%94%ae%e8%8f%9c%e5%8d%95take-back-my-ownership.html" title="Win7/Vista高级用户必备的右键菜单Take back my Ownership! (2009/12/06)">Win7/Vista高级用户必备的右键菜单Take back my Ownership!</a> </li>
	<li><a href="http://www.imkevinyang.com/2009/09/%e8%a7%a3%e5%86%b3silverlight%e6%97%a0%e6%b3%95%e8%b0%83%e8%af%95%e7%9a%84%e9%97%ae%e9%a2%98.html" title="解决Silverlight无法调试的问题 (2009/09/01)">解决Silverlight无法调试的问题</a> </li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://www.imkevinyang.com/2010/05/vs2010%e7%9a%84ui%e8%ae%be%e8%ae%a1%e5%a4%b1%e8%af%af.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Visual Assist代码提示使用的字符串模糊匹配算法</title>
		<link>http://www.imkevinyang.com/2009/09/visual-assist%e4%bb%a3%e7%a0%81%e6%8f%90%e7%a4%ba%e4%bd%bf%e7%94%a8%e7%9a%84%e5%ad%97%e7%ac%a6%e4%b8%b2%e6%a8%a1%e7%b3%8a%e5%8c%b9%e9%85%8d%e7%ae%97%e6%b3%95.html</link>
		<comments>http://www.imkevinyang.com/2009/09/visual-assist%e4%bb%a3%e7%a0%81%e6%8f%90%e7%a4%ba%e4%bd%bf%e7%94%a8%e7%9a%84%e5%ad%97%e7%ac%a6%e4%b8%b2%e6%a8%a1%e7%b3%8a%e5%8c%b9%e9%85%8d%e7%ae%97%e6%b3%95.html#comments</comments>
		<pubDate>Mon, 28 Sep 2009 04:44:00 +0000</pubDate>
		<dc:creator>Kevin Yang</dc:creator>
				<category><![CDATA[代码库]]></category>
		<category><![CDATA[技术随笔]]></category>
		<category><![CDATA[Visual Assist]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[代码提示]]></category>
		<category><![CDATA[字符串匹配]]></category>
		<category><![CDATA[智能感知]]></category>
		<category><![CDATA[智能提示]]></category>
		<category><![CDATA[算法]]></category>

		<guid isPermaLink="false">http://www.imkevinyang.com/2009/09/visual-assist%e4%bb%a3%e7%a0%81%e6%8f%90%e7%a4%ba%e4%bd%bf%e7%94%a8%e7%9a%84%e5%ad%97%e7%ac%a6%e4%b8%b2%e6%a8%a1%e7%b3%8a%e5%8c%b9%e9%85%8d%e7%ae%97%e6%b3%95.html</guid>
		<description><![CDATA[<p>Visual Assist是Visual Studio上一个很强大的插件。特别是在代码提示方面，相比Visual Studio自带的要强很多。</p>
<p>Visual Studio自带的代码提示（智能感知）功能会根据我们敲入的字符串，找到相似的类或者方法等。但是它的匹配规则非常简单，就是前向匹配。例如当我们输入了Str&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>Visual Assist是Visual Studio上一个很强大的插件。特别是在代码提示方面，相比Visual Studio自带的要强很多。</p>
<p>Visual Studio自带的代码提示（智能感知）功能会根据我们敲入的字符串，找到相似的类或者方法等。但是它的匹配规则非常简单，就是前向匹配。例如当我们输入了String字符串，那么Visual Studio会列出String,StringBuilder,StringComparer等以“String”打头的字符串。这样的设计其实是非常不够用的。稍微敲快一些漏掉一两个字母是很正常的事情，但是在VS中就无法享受代码提示带来的便捷了。好在Visual Assist改进了这一点。</p>
<p>VA采用字符串模糊匹配的算法，即使你漏过了其中几个字母，或者当你想要搜索含有某个字符串的类、方法等的时候，VA都可以很好的列出你想找的东西。</p>
<p>例如，我想使用SqlConnectionStringBuilder这个类，但是这个类名太长了。那么我们只需要输入“sqlconbui”字符串即可。又或者，我们想看看类库中有什么和String相关的，我们只需要输入String即可。</p>
<p>一直很好奇它这个匹配算法是怎么实现的，在论坛问了别人都没什么人感兴趣。自己研究了一下，我觉得算法要求可以这样来描述：</p>
<blockquote><p>源字符串在经过若干次插入操作之后，能够变换成目标字符串。那么就说源字符串成功匹配到了目标字符串。否则不匹配。</p>
<p>插入操作，指的是在源字符串的任意位置上插入任意长度的字符串。 </p>
</blockquote>
<p>自己写了个大概的算法实现（C#版）：</p>
<pre class="csharpcode"><span class="rem">/// &lt;summary&gt;</span>
<span class="rem">/// 字符串模糊匹配。</span>
<span class="rem">/// &lt;/summary&gt;</span>
<span class="rem">/// &lt;param name=&quot;source&quot;&gt;&lt;/param&gt;</span>
<span class="rem">/// &lt;param name=&quot;search&quot;&gt;&lt;/param&gt;</span>
<span class="rem">/// &lt;returns&gt;&lt;/returns&gt;</span>
<span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">bool</span> FuzzySearch(String source, String search)
{
    <span class="kwrd">if</span> (String.IsNullOrEmpty(source))
    {
        <span class="kwrd">throw</span> <span class="kwrd">new</span> ArgumentNullException(<span class="str">&quot;source&quot;</span>);
    }
    <span class="kwrd">if</span> (String.IsNullOrEmpty(search))
    {
        <span class="kwrd">return</span> <span class="kwrd">true</span>;
    }
    <span class="rem">// 不区分大小写</span>
    source = source.ToLowerInvariant();
    search = search.ToLowerInvariant();
    <span class="kwrd">int</span> index = source.IndexOf(search[0]);
    <span class="kwrd">for</span> (<span class="kwrd">short</span> i = 1; i &lt; search.Length; i++)
    {
        <span class="kwrd">char</span> ch = search[i];
        index = source.IndexOf(ch, index + 1);
        <span class="kwrd">if</span> (index &lt; 0)
        {
            <span class="kwrd">return</span> <span class="kwrd">false</span>;
        }
    }
    <span class="kwrd">return</span> <span class="kwrd">true</span>;
}</pre>
<p>测试了一下，“sqlconbui”能够成功匹配到SqlConnectionStringBuilder。不过验证了其他几个字符串，发现和VA的算法还是有点差别的，感觉我这个匹配相比它的更宽松的样子。</p>
<p align="right">——<a href="http://www.imkevinyang.com/"><em><strong>Kevin Yang</strong></em></a></p>

	标签：<a href="http://www.imkevinyang.com/tags/visual-assist" title="Visual Assist" rel="tag">Visual Assist</a>, <a href="http://www.imkevinyang.com/tags/visual-studio" title="Visual Studio" rel="tag">Visual Studio</a>, <a href="http://www.imkevinyang.com/categories/techarticles/codebase" title="代码库" rel="tag">代码库</a>, <a href="http://www.imkevinyang.com/tags/%e4%bb%a3%e7%a0%81%e6%8f%90%e7%a4%ba" title="代码提示" rel="tag">代码提示</a>, <a href="http://www.imkevinyang.com/tags/%e5%ad%97%e7%ac%a6%e4%b8%b2%e5%8c%b9%e9%85%8d" title="字符串匹配" rel="tag">字符串匹配</a>, <a href="http://www.imkevinyang.com/categories/techarticles" title="技术随笔" rel="tag">技术随笔</a>, <a href="http://www.imkevinyang.com/tags/%e6%99%ba%e8%83%bd%e6%84%9f%e7%9f%a5" title="智能感知" rel="tag">智能感知</a>, <a href="http://www.imkevinyang.com/tags/%e6%99%ba%e8%83%bd%e6%8f%90%e7%a4%ba" title="智能提示" rel="tag">智能提示</a>, <a href="http://www.imkevinyang.com/tags/%e7%ae%97%e6%b3%95" title="算法" rel="tag">算法</a><br />

	<h4 style="background-color:#3B3B3B;border-bottom:2px groove gray;color:#F2F2F2;margin-top:20px;padding:6px 6px 6px 15px;margin:20px 0px 0px 0px">你可能对下面的文章感兴趣</h4>
	<ul class="st-related-posts">
	<li><a href="http://www.imkevinyang.com/2010/09/visual-studio-2010%e9%87%8d%e5%91%bd%e5%90%8d%e9%87%8d%e6%9e%84%e6%97%b6%e5%87%ba%e7%8e%b0%e7%9a%84%e9%97%ae%e9%a2%98.html" title="Visual Studio 2010重命名重构时出现的问题 (2010/09/29)">Visual Studio 2010重命名重构时出现的问题</a> </li>
	<li><a href="http://www.imkevinyang.com/2009/09/visual-studio%e5%b0%8f%e8%b4%b4%e5%a3%ab%e5%8a%a0%e4%ba%86try-catch%e4%b9%9f%e8%83%bd%e8%87%aa%e5%8a%a8%e5%ae%9a%e4%bd%8d%e5%88%b0%e5%bc%82%e5%b8%b8%e4%bb%a3%e7%a0%81.html" title="Visual Studio小贴士&mdash;&mdash;加了Try-Catch也能自动定位到异常代码 (2009/09/18)">Visual Studio小贴士&mdash;&mdash;加了Try-Catch也能自动定位到异常代码</a> </li>
	<li><a href="http://www.imkevinyang.com/2009/05/visual-studio%e7%bb%9f%e8%ae%a1%e6%9c%89%e6%95%88%e4%bb%a3%e7%a0%81%e8%a1%8c%e6%95%b0.html" title="Visual Studio统计有效代码行数 (2009/05/22)">Visual Studio统计有效代码行数</a> </li>
	<li><a href="http://www.imkevinyang.com/2010/07/visual-studio%e7%bc%96%e8%be%91%e5%99%a8%e4%b8%80%e6%ac%a1%e7%bc%a9%e8%bf%9b%e5%8f%8d%e7%bc%a9%e8%bf%9b4%e4%b8%aa%e7%a9%ba%e6%a0%bc.html" title="Visual Studio编辑器一次缩进/反缩进4个空格 (2010/07/04)">Visual Studio编辑器一次缩进/反缩进4个空格</a> </li>
	<li><a href="http://www.imkevinyang.com/2010/05/vs2010%e7%9a%84ui%e8%ae%be%e8%ae%a1%e5%a4%b1%e8%af%af.html" title="VS2010的UI设计失误 (2010/05/31)">VS2010的UI设计失误</a> </li>
	<li><a href="http://www.imkevinyang.com/2011/04/vs%e7%bc%96%e8%af%91%e6%97%b6%e8%87%aa%e5%8a%a8%e5%bc%95%e7%94%a8debugrelease%e7%89%88%e6%9c%ac%e7%9a%84dll.html" title="VS编译时自动引用Debug|Release版本的dll (2011/04/10)">VS编译时自动引用Debug|Release版本的dll</a> </li>
	<li><a href="http://www.imkevinyang.com/2009/08/%e4%bd%bf%e7%94%a8%e6%ad%a3%e5%88%99%e8%a1%a8%e8%be%be%e5%bc%8f%e6%89%be%e5%87%ba%e4%b8%8d%e5%8c%85%e5%90%ab%e7%89%b9%e5%ae%9a%e5%ad%97%e7%ac%a6%e4%b8%b2%e7%9a%84%e6%9d%a1%e7%9b%ae.html" title="使用正则表达式找出不包含特定字符串的条目 (2009/08/04)">使用正则表达式找出不包含特定字符串的条目</a> </li>
	<li><a href="http://www.imkevinyang.com/2009/09/%e8%a7%a3%e5%86%b3silverlight%e6%97%a0%e6%b3%95%e8%b0%83%e8%af%95%e7%9a%84%e9%97%ae%e9%a2%98.html" title="解决Silverlight无法调试的问题 (2009/09/01)">解决Silverlight无法调试的问题</a> </li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://www.imkevinyang.com/2009/09/visual-assist%e4%bb%a3%e7%a0%81%e6%8f%90%e7%a4%ba%e4%bd%bf%e7%94%a8%e7%9a%84%e5%ad%97%e7%ac%a6%e4%b8%b2%e6%a8%a1%e7%b3%8a%e5%8c%b9%e9%85%8d%e7%ae%97%e6%b3%95.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Visual Studio小贴士&#8212;&#8212;加了Try-Catch也能自动定位到异常代码</title>
		<link>http://www.imkevinyang.com/2009/09/visual-studio%e5%b0%8f%e8%b4%b4%e5%a3%ab%e5%8a%a0%e4%ba%86try-catch%e4%b9%9f%e8%83%bd%e8%87%aa%e5%8a%a8%e5%ae%9a%e4%bd%8d%e5%88%b0%e5%bc%82%e5%b8%b8%e4%bb%a3%e7%a0%81.html</link>
		<comments>http://www.imkevinyang.com/2009/09/visual-studio%e5%b0%8f%e8%b4%b4%e5%a3%ab%e5%8a%a0%e4%ba%86try-catch%e4%b9%9f%e8%83%bd%e8%87%aa%e5%8a%a8%e5%ae%9a%e4%bd%8d%e5%88%b0%e5%bc%82%e5%b8%b8%e4%bb%a3%e7%a0%81.html#comments</comments>
		<pubDate>Fri, 18 Sep 2009 05:07:00 +0000</pubDate>
		<dc:creator>Kevin Yang</dc:creator>
				<category><![CDATA[工具技巧]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[小贴士]]></category>
		<category><![CDATA[异常]]></category>
		<category><![CDATA[断点]]></category>
		<category><![CDATA[调试]]></category>

		<guid isPermaLink="false">http://www.imkevinyang.com/2009/09/visual-studio%e5%b0%8f%e8%b4%b4%e5%a3%ab%e5%8a%a0%e4%ba%86try-catch%e4%b9%9f%e8%83%bd%e8%87%aa%e5%8a%a8%e5%ae%9a%e4%bd%8d%e5%88%b0%e5%bc%82%e5%b8%b8%e4%bb%a3%e7%a0%81.html</guid>
		<description><![CDATA[<p>Visual Studio的调试功能非常强大。当异常发生的时候，能够自动定位到异常发生的地方。但是如果你在代码外层显式的加上了Try-Catch异常捕获的时候，默认情况下，Visual Studio会直接跳到异常处理代码块，而不是出现异常的代码行。</p>
<pre class="csharpcode"><span class="kwrd">namespace</span> BreakOnException
{
    <span class="kwrd">cl&#8230;</span></pre>]]></description>
			<content:encoded><![CDATA[<p>Visual Studio的调试功能非常强大。当异常发生的时候，能够自动定位到异常发生的地方。但是如果你在代码外层显式的加上了Try-Catch异常捕获的时候，默认情况下，Visual Studio会直接跳到异常处理代码块，而不是出现异常的代码行。</p>
<pre class="csharpcode"><span class="kwrd">namespace</span> BreakOnException
{
    <span class="kwrd">class</span> Program
    {
        <span class="kwrd">static</span> <span class="kwrd">void</span> Main(<span class="kwrd">string</span>[] args)
        {
            <span class="kwrd">try</span>
            {
                Program p = <span class="kwrd">null</span>;
                Console.WriteLine(p.GetHashCode());
            }
            <span class="kwrd">catch</span> (System.Exception ex)
            {

            }
        }
    }
}</pre>
<p>上面的代码会抛出经典的NullReferrenceException。但是当你在调试状态下运行时，Visual Studio会将代码停在catch这一行，而不是Console.WriteLine这一行。</p>
<p><img style="border-right-width: 0px; margin: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.imkevinyang.com/wp-content/uploads/2009/10/image_thumb5.png" width="304" height="116" /> </p>
<p>如果代码简单那倒无所谓，但是假想我们的代码是经过层层的函数调用，最外层却加了这么个Try-Catch，那么异常函数调用内抛出了异常，我们也很难定位到异常出错的代码（StackTrace也只能定位哪一个函数调用出错了）。</p>
<p>这个行为可以通过Debug菜单中的Exception….菜单进行设置。</p>
<p><img style="border-right-width: 0px; margin: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.imkevinyang.com/wp-content/uploads/2009/10/image_thumb6.png" width="558" height="214" /> </p>
<p>打开此菜单，在CLR异常的Thrown列打上勾，那么以后遇到CLR的异常就不再是定位到用户处理代码了，而是直接停在抛出异常的代码上。这样可以大大方便我们调试程序的Bug。</p>
<p><img style="border-right-width: 0px; margin: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.imkevinyang.com/wp-content/uploads/2009/10/image_thumb7.png" width="465" height="151" /> </p>
<p align="right">——<a href="http://www.imkevinyang.com/"><em><strong>Kevin Yang</strong></em></a></p>

	标签：<a href="http://www.imkevinyang.com/tags/tips" title="Tips" rel="tag">Tips</a>, <a href="http://www.imkevinyang.com/tags/visual-studio" title="Visual Studio" rel="tag">Visual Studio</a>, <a href="http://www.imkevinyang.com/tags/%e5%b0%8f%e8%b4%b4%e5%a3%ab" title="小贴士" rel="tag">小贴士</a>, <a href="http://www.imkevinyang.com/categories/techarticles/toolskills-techarticles" title="工具技巧" rel="tag">工具技巧</a>, <a href="http://www.imkevinyang.com/tags/%e5%bc%82%e5%b8%b8" title="异常" rel="tag">异常</a>, <a href="http://www.imkevinyang.com/tags/%e6%96%ad%e7%82%b9" title="断点" rel="tag">断点</a>, <a href="http://www.imkevinyang.com/tags/%e8%b0%83%e8%af%95" title="调试" rel="tag">调试</a><br />

	<h4 style="background-color:#3B3B3B;border-bottom:2px groove gray;color:#F2F2F2;margin-top:20px;padding:6px 6px 6px 15px;margin:20px 0px 0px 0px">你可能对下面的文章感兴趣</h4>
	<ul class="st-related-posts">
	<li><a href="http://www.imkevinyang.com/2009/09/blend%e5%b0%8f%e8%b4%b4%e5%a3%ab%e6%94%b9%e5%8f%98%e9%bc%a0%e6%a0%87%e6%bb%9a%e8%bd%ae%e7%9a%84%e9%bb%98%e8%ae%a4%e8%a1%8c%e4%b8%ba-2.html" title="Blend小贴士&mdash;&mdash;改变鼠标滚轮的默认行为 (2009/09/18)">Blend小贴士&mdash;&mdash;改变鼠标滚轮的默认行为</a> </li>
	<li><a href="http://www.imkevinyang.com/2009/08/firebug%e5%9c%a8edithtml%e6%97%b6%e4%b8%a2%e5%a4%b1%e4%ba%8b%e4%bb%b6%e5%a4%84%e7%90%86%e5%87%bd%e6%95%b0-2.html" title="Firebug在EditHtml时丢失事件处理函数 (2009/08/19)">Firebug在EditHtml时丢失事件处理函数</a> </li>
	<li><a href="http://www.imkevinyang.com/2009/05/javascript%e4%b8%ad%e8%8e%b7%e5%8f%96%e5%87%ba%e9%94%99%e4%bb%a3%e7%a0%81%e6%89%80%e5%9c%a8%e6%96%87%e4%bb%b6%e5%8f%8a%e8%a1%8c%e6%95%b0.html" title="Javascript中获取出错代码所在文件及行数 (2009/05/18)">Javascript中获取出错代码所在文件及行数</a> </li>
	<li><a href="http://www.imkevinyang.com/2011/06/onenote-tips-%e6%b7%b7%e5%90%88%e4%bd%bf%e7%94%a8%e4%b8%ad%e8%8b%b1%e6%96%87%e5%ad%97%e4%bd%93.html" title="OneNote Tips — 混合使用中英文字体 (2011/06/16)">OneNote Tips — 混合使用中英文字体</a> </li>
	<li><a href="http://www.imkevinyang.com/2010/07/sql-tipsupdate%e8%af%ad%e5%8f%a5%e4%b9%9f%e4%bd%bf%e7%94%a8%e8%a1%a8%e5%88%ab%e5%90%8dtable-alias.html" title="Sql Tips——Update语句也使用表别名(Table Alias) (2010/07/02)">Sql Tips——Update语句也使用表别名(Table Alias)</a> </li>
	<li><a href="http://www.imkevinyang.com/2009/09/visual-assist%e4%bb%a3%e7%a0%81%e6%8f%90%e7%a4%ba%e4%bd%bf%e7%94%a8%e7%9a%84%e5%ad%97%e7%ac%a6%e4%b8%b2%e6%a8%a1%e7%b3%8a%e5%8c%b9%e9%85%8d%e7%ae%97%e6%b3%95.html" title="Visual Assist代码提示使用的字符串模糊匹配算法 (2009/09/28)">Visual Assist代码提示使用的字符串模糊匹配算法</a> </li>
	<li><a href="http://www.imkevinyang.com/2010/09/visual-studio-2010%e9%87%8d%e5%91%bd%e5%90%8d%e9%87%8d%e6%9e%84%e6%97%b6%e5%87%ba%e7%8e%b0%e7%9a%84%e9%97%ae%e9%a2%98.html" title="Visual Studio 2010重命名重构时出现的问题 (2010/09/29)">Visual Studio 2010重命名重构时出现的问题</a> </li>
	<li><a href="http://www.imkevinyang.com/2009/05/visual-studio%e7%bb%9f%e8%ae%a1%e6%9c%89%e6%95%88%e4%bb%a3%e7%a0%81%e8%a1%8c%e6%95%b0.html" title="Visual Studio统计有效代码行数 (2009/05/22)">Visual Studio统计有效代码行数</a> </li>
	<li><a href="http://www.imkevinyang.com/2010/07/visual-studio%e7%bc%96%e8%be%91%e5%99%a8%e4%b8%80%e6%ac%a1%e7%bc%a9%e8%bf%9b%e5%8f%8d%e7%bc%a9%e8%bf%9b4%e4%b8%aa%e7%a9%ba%e6%a0%bc.html" title="Visual Studio编辑器一次缩进/反缩进4个空格 (2010/07/04)">Visual Studio编辑器一次缩进/反缩进4个空格</a> </li>
	<li><a href="http://www.imkevinyang.com/2010/05/vs2010%e7%9a%84ui%e8%ae%be%e8%ae%a1%e5%a4%b1%e8%af%af.html" title="VS2010的UI设计失误 (2010/05/31)">VS2010的UI设计失误</a> </li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://www.imkevinyang.com/2009/09/visual-studio%e5%b0%8f%e8%b4%b4%e5%a3%ab%e5%8a%a0%e4%ba%86try-catch%e4%b9%9f%e8%83%bd%e8%87%aa%e5%8a%a8%e5%ae%9a%e4%bd%8d%e5%88%b0%e5%bc%82%e5%b8%b8%e4%bb%a3%e7%a0%81.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>解决Silverlight无法调试的问题</title>
		<link>http://www.imkevinyang.com/2009/09/%e8%a7%a3%e5%86%b3silverlight%e6%97%a0%e6%b3%95%e8%b0%83%e8%af%95%e7%9a%84%e9%97%ae%e9%a2%98.html</link>
		<comments>http://www.imkevinyang.com/2009/09/%e8%a7%a3%e5%86%b3silverlight%e6%97%a0%e6%b3%95%e8%b0%83%e8%af%95%e7%9a%84%e9%97%ae%e9%a2%98.html#comments</comments>
		<pubDate>Tue, 01 Sep 2009 06:26:00 +0000</pubDate>
		<dc:creator>Kevin Yang</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[疑难杂症]]></category>
		<category><![CDATA[Silverlight无法调试]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[调试]]></category>

		<guid isPermaLink="false">http://www.imkevinyang.com/2009/08/%e8%a7%a3%e5%86%b3silverlight%e8%b0%83%e8%af%95%e7%8a%b6%e6%80%81%e4%b8%8b%e6%97%a0%e6%b3%95%e8%b7%9f%e8%bf%9b%e6%96%ad%e7%82%b9%e7%9a%84%e9%97%ae%e9%a2%98.html</guid>
		<description><![CDATA[问题描述
<p>在Silverlight开发过程中，经常时不时的会碰到Silverlight无法调试的问题。我就遇到下面几种情况：</p>
<p>1. Web Application+Silverlight，F5进入调试状态之后无法跟进Silverlight程序中下的断点</p>
<p>2. 项目中有两个Silverlight工程，其中一个Si&#8230;</p>]]></description>
			<content:encoded><![CDATA[<h2>问题描述</h2>
<p>在Silverlight开发过程中，经常时不时的会碰到Silverlight无法调试的问题。我就遇到下面几种情况：</p>
<p>1. Web Application+Silverlight，F5进入调试状态之后无法跟进Silverlight程序中下的断点</p>
<p>2. 项目中有两个Silverlight工程，其中一个Silverlight程序中有一个鼠标点击事件会将当前页面导航到另外一个Silverlight程序的承载页面。第一个Silverlight程序断点正常，但是第二个Silverlight程序中的断点不能自动停下来</p>
<p>3. 无论是在TestPage模式下调试还是在Web工程上调试，只要打开了Silverlight调试开关，那么启动的时候会提示“<strong><font color="#008000">Unable to start debugging. Cannot locate Microsoft Internet Explorer</font></strong>”。如果你是直接Ctrl+F5运行，有时候也会出现一样的问题。</p>
<h2>单个Silverlight工程无法调试</h2>
<p>对于第一个问题，请检查如下设置是否正确：</p>
<p>1. <strong><font color="#008000">确认启用了Silverlight调试</font></strong>。双击Asp.Net工程中的属性文件夹打开属性设置页，找到Web一栏，在此页卡的最下面有几个调试选项，如下图所示：</p>
<p><img style="border-right-width: 0px; margin: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.imkevinyang.com/wp-content/uploads/2009/08/image_thumb5.png" width="166" height="116" /> <img style="border-right-width: 0px; margin: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.imkevinyang.com/wp-content/uploads/2009/08/image_thumb6.png" width="511" height="42" /></p>
<p>确认最后一项“Silverlight”之前的勾是勾上的。</p>
<p>2. <strong><font color="#008000">确保浏览器访问的Xap包是最新的</font></strong>。检查IE是否已经清除了缓存，或者ClientBin中的Xap因为某些原因没能更新（如因配置管理导致无法覆盖）</p>
<p>3. <strong><font color="#008000">检查Asp.Net工程是否绑定了Silverlight应用</font></strong>。可以通过asp.net工程的属性面板中的Silverlight Application页卡查看是否绑定成功。如下：</p>
<p><img style="border-right-width: 0px; margin: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Silverlight Applications Settings" border="0" alt="Silverlight Applications Settings" src="http://www.imkevinyang.com/wp-content/uploads/2009/09/image_thumb.png" width="331" height="204" /></p>
<p>4. <strong><font color="#008000">检查Silverlight工程的StartupObject是否设置正确</font></strong>。有时候我们对工程的命名空间进行重命名，会导致Silverlight应用程序的入口对象失效，从而导致无法启动等情况。</p>
<p><img style="border-right-width: 0px; margin: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Silverlight Application Startup Object" border="0" alt="Silverlight Application Startup Object" src="http://www.imkevinyang.com/wp-content/uploads/2009/09/image_thumb1.png" width="453" height="131" /></p>
<h2>IE8下无法同时调试多个Silverlight工程？！</h2>
<p>IE8和以往的IE不大一样，它的多标签是采用多进程的方式来实现的。整个窗口是一个框架进程，每个Tab标签页是一个独立的子进程（实际上，IE8会根据内存动态控制Tab进程的数目，因此多个标签页可能会共存于同一个进程之中）。当你尝试在多个标签页中打开不同的Silverlight应用程序时，例如从SilverlightApplication1中打开新页面到SilverlightApplication2页面，这个时候你会发现，SilverlightApplication2应用程序无法调试。</p>
<p>这是因为，<strong><font color="#008000">Visual Studio除了启动窗口进程之外，不会自动帮我们Attach其他的包含Silverlight应用程序的进程，如果我们需要在多个标签页（或者多个窗口）中同时调试不同的Silverlight应用程序，那么我们必须自己手动Attach这些进程</font></strong>。</p>
<p>举个简单的例子，我有两个Silverlight工程，其中SilverlightApplication1中包含链接指向SilverlightApplication2页面，点击链接会在新标签页中打开SilverlightApplication2的承载页面。</p>
<p>为了Attach相应的进程，首先我们需要找到SilverlightApplication2承载页面对应的进程。打开ProcessExplorer，我们可以看到三个进程。</p>
<p><img style="border-right-width: 0px; margin: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.imkevinyang.com/wp-content/uploads/2009/09/image_thumb2.png" width="232" height="59" /></p>
<p>其中的ID为4528的是父进程，也就是框架进程，用于管理不同的标签进程之间的通信等事务。5160和5248分别对应着两个标签页进程。至于哪个对应哪个我们在这里无法根据进程号确定。</p>
<p>我们再打开Visual Studio中的Attach窗口（菜单=&gt;Debug=&gt;Attach to process…）</p>
<p><img style="border-right-width: 0px; margin: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.imkevinyang.com/wp-content/uploads/2009/09/image_thumb3.png" width="510" height="185" /></p>
<p>这里列出了所有系统可用的进程清单，我们可以看到三个IE进程，其中一个是灰色的，这表示了这个进程已经被Attach到Visual Studio的调试器上了。排除了框架进程4258外，就剩下5248这个进程了，这个进程就是我们要找的SilverlightApplication2对应的承载页面的进程了。选中之后Attach到调试器上，我们发现，SilverlightApplication2中的断点还是显示为空心红圈，依然无法调试。</p>
<p>这是因为我们指定的进程代码类型不正确。我们注意到，上图中最上面有一个Attach to，后面显示的是Automatic，这个代表着Visual Studio的调试器会自动帮我们选择进程的调试类型，例如是托管代码调试，还是脚本调试，等等。我们选中5248这个进程，发现Visual Studio给我们选择的方式是脚本调试。</p>
<p><img style="border-right-width: 0px; margin: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.imkevinyang.com/wp-content/uploads/2009/09/image_thumb4.png" width="504" height="144" /></p>
<p>在Visual Studio中，脚本调试和Silverlight调试是不能共存的，这也就是为什么有时候你按下F5的时候，Visual Studio会提示你，调试Silverlight程序会暂时关闭脚本调试的功能。因此在脚本调试下，我们无法跟进Silverlight应用程序的断点。</p>
<p>这里额外说一点，IE8高级选项中的禁用脚本调试设置对Visual Studio一点影响都没有，因为Visual Studio 2008在调试器启动的时候会自动启用脚本调试（可以通过注册表禁用此特性），除非在Web Application属性中打开了Silverlight调试。</p>
<p>回到刚才的问题，由于Visual Studio帮我们自动选择的调试类型有误，导致我们无法调试SilverlightApplication2，因此我们需要手动指定Attach类型。点击Attach to后侧的select按钮。</p>
<p><img style="border-right-width: 0px; margin: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.imkevinyang.com/wp-content/uploads/2009/09/image_thumb5.png" width="308" height="211" /></p>
<p>在弹出的选择代码类型窗口中勾选上Silverlight。确定之后再次Attach，我们发现，这一次，断点真的起作用了。</p>
<p>当然，如果这种方式比较麻烦的话，我们也可以通过改变IE8的Tab进程创建方式来让不同标签页共存于一个进程中。在注册表HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main下面有一个TabProcGrowth键值（DWORD类型），当其设置为0时， IE框架和Tab工作在一个进程里面，Tab采用线程的方式创建，同时IE的保护模式（Protect Mode）会关闭。TabProcGrowth=1时IE框架和Tab工作在不同的进程里面。TabProcGrowth&gt;1时，此值将决定IE8最多创建的Tab进程数目。如果TabProcGrowth 不存在，则会根据可用的物理内存数量决定Tab进程的数量。</p>
<h2>调试时无法打开IE窗口的问题</h2>
<p>这个问题是我最近才遇到的，我也不知道为什么突然之间，我的Silverlight工程按下F5的时候无法调试，弹出下面这个对话框：Unable to start debugging. Cannot locate Microsoft Internet Explorer.</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.imkevinyang.com/wp-content/uploads/2009/12/image_thumb15.png" width="248" height="141" /> </p>
<p>如果直接运行，那么能够打开，但是打开之后Visual Studio还是会弹出一样的错误。</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.imkevinyang.com/wp-content/uploads/2009/12/image_thumb16.png" width="257" height="134" /> </p>
<p>这个问题折腾了我半天，我尝试了重启电脑，重装Silverlight Tools，新建干净的测试工程，修改系统和Visual Studio的默认浏览器（注意，系统和Visual Studio的默认浏览器是独立设置的）均以失败告终。Google了很久，Silverlight官方论坛上倒是有不少帖子和这个相关的，但我细细看了之后发现没有一个回帖能够解决我的问题的。有个发帖的家伙问题是解决了，但是不把怎么解决的说一下就跑了，强烈bs一下这种人！</p>
<p>话说回来，我最后是怎么解决这个问题的呢，是用了Process Monitor这个小工具（微软Sysinternal荣誉出品！）。之前有一次asp.net网站的GlobalError里头出现了一个“文件不存在”的HTTPException，查了半天没查出来，后来使用这个工具监视了一下WebDevServ.exe进程之后发现该进程尝试去访问某个不存在的文件。</p>
<blockquote><p>Process Monitor，可以监控当前系统中所有进程的活动，包括对文件系统的操作，读写注册表，网络访问以及线程活动等等，非常实用的调试维护工具。</p>
</blockquote>
<p>我打开这个工具，选择监视进程为devenv.exe。在Visual Studio中F5开始调试，立即弹出出错对话框，OK，把PM暂停一下，否则条目太多了。</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.imkevinyang.com/wp-content/uploads/2009/12/image_thumb17.png" width="298" height="98" /> </p>
<p>但是事件条目还是太多了，所以我把Result为SUCCESS的条目过滤掉，因为我们只关注那些失败的条目。</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.imkevinyang.com/wp-content/uploads/2009/12/image_thumb18.png" width="271" height="171" /> </p>
<p>然后对日志条目进行细致的排查，终于发现了问题根源：</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.imkevinyang.com/wp-content/uploads/2009/12/image_thumb19.png" width="546" height="45" /> </p>
<p>原来Visual Studio在调试或者运行的时候会去读取注册表中的HKLM\Software\Microsoft\Windows\CurrentVersion\App Paths\iexplore.exe项，然后读取不到，因而才报那个错误。难怪提示Cannot locate Microsoft internet explorer呢。</p>
<p>我打开regedit注册表编辑器，找到这个路径，然后把缺失的项加上去，重新回到Visual Studio中F5，终于可以了，内牛满面~</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.imkevinyang.com/wp-content/uploads/2009/12/image_thumb20.png" width="330" height="156" /> </p>
<p>希望我的解决方法能够给你一些启发，以后遇到类似莫名其妙的问题，可以想到使用PM这个工具去排查问题。</p>
<p><font color="#ff0000">update</font>: 更新了新的症状（F5调试的时候弹出cannot locate microsoft internet explorer的对话框）的解决办法。</p>
<p align="right">——<a href="http://www.imkevinyang.com/"><em><strong>Kevin Yang</strong></em></a></p>

	标签：<a href="http://www.imkevinyang.com/categories/techarticles/silverlight" title="Silverlight" rel="tag">Silverlight</a>, <a href="http://www.imkevinyang.com/tags/silverlight" title="Silverlight" rel="tag">Silverlight</a>, <a href="http://www.imkevinyang.com/tags/silverlight%e6%97%a0%e6%b3%95%e8%b0%83%e8%af%95" title="Silverlight无法调试" rel="tag">Silverlight无法调试</a>, <a href="http://www.imkevinyang.com/tags/visual-studio" title="Visual Studio" rel="tag">Visual Studio</a>, <a href="http://www.imkevinyang.com/categories/techarticles/knottyproblems" title="疑难杂症" rel="tag">疑难杂症</a>, <a href="http://www.imkevinyang.com/tags/%e8%b0%83%e8%af%95" title="调试" rel="tag">调试</a><br />

	<h4 style="background-color:#3B3B3B;border-bottom:2px groove gray;color:#F2F2F2;margin-top:20px;padding:6px 6px 6px 15px;margin:20px 0px 0px 0px">你可能对下面的文章感兴趣</h4>
	<ul class="st-related-posts">
	<li><a href="http://www.imkevinyang.com/2009/09/blend%e5%b0%8f%e8%b4%b4%e5%a3%ab%e6%94%b9%e5%8f%98%e9%bc%a0%e6%a0%87%e6%bb%9a%e8%bd%ae%e7%9a%84%e9%bb%98%e8%ae%a4%e8%a1%8c%e4%b8%ba-2.html" title="Blend小贴士&mdash;&mdash;改变鼠标滚轮的默认行为 (2009/09/18)">Blend小贴士&mdash;&mdash;改变鼠标滚轮的默认行为</a> </li>
	<li><a href="http://www.imkevinyang.com/2009/08/firebug%e5%9c%a8edithtml%e6%97%b6%e4%b8%a2%e5%a4%b1%e4%ba%8b%e4%bb%b6%e5%a4%84%e7%90%86%e5%87%bd%e6%95%b0-2.html" title="Firebug在EditHtml时丢失事件处理函数 (2009/08/19)">Firebug在EditHtml时丢失事件处理函数</a> </li>
	<li><a href="http://www.imkevinyang.com/2009/02/silverlight-2-rtm-%e5%a4%9a%e5%9b%bd%e8%af%ad%e8%a8%80%e6%94%af%e6%8c%81%ef%bc%88%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f%e6%9c%ac%e5%9c%b0%e5%8c%96%ef%bc%89.html" title="Silverlight 2 RTM 多国语言支持（应用程序本地化） (2009/02/28)">Silverlight 2 RTM 多国语言支持（应用程序本地化）</a> </li>
	<li><a href="http://www.imkevinyang.com/2009/03/silverlight-2%e5%8a%a8%e6%80%81%e5%8a%a0%e8%bd%bdxap%e5%8c%85%e4%b8%ad%e7%9a%84%e7%a8%8b%e5%ba%8f%e9%9b%86.html" title="Silverlight 2动态加载Xap包中的程序集 (2009/03/02)">Silverlight 2动态加载Xap包中的程序集</a> </li>
	<li><a href="http://www.imkevinyang.com/2010/05/silverlight-4ria-services-%e6%90%9c%e7%b4%a2%e5%bc%95%e6%93%8e%e4%bc%98%e5%8c%96seo.html" title="Silverlight 4+RIA Services&#8211;搜索引擎优化(SEO) (2010/05/04)">Silverlight 4+RIA Services&#8211;搜索引擎优化(SEO)</a> </li>
	<li><a href="http://www.imkevinyang.com/2009/04/silverlight-seo%ef%bc%88%e6%90%9c%e7%b4%a2%e5%bc%95%e6%93%8e%e4%bc%98%e5%8c%96%ef%bc%89%e7%99%bd%e7%9a%ae%e4%b9%a6.html" title="Silverlight SEO（搜索引擎优化）白皮书 (2009/04/06)">Silverlight SEO（搜索引擎优化）白皮书</a> </li>
	<li><a href="http://www.imkevinyang.com/2009/03/silverlight2-%e5%8a%a8%e6%80%81%e5%8a%a0%e8%bd%bd%e7%a8%8b%e5%ba%8f%e9%9b%86-ondemand%e6%a8%a1%e5%bc%8fdynamic-load-assembly.html" title="Silverlight2 动态加载程序集&#8212;OnDemand模式(Dynamic Load Assembly) (2009/03/02)">Silverlight2 动态加载程序集&#8212;OnDemand模式(Dynamic Load Assembly)</a> </li>
	<li><a href="http://www.imkevinyang.com/2011/09/silverlight%e4%b8%ad%e6%97%a0%e6%b3%95%e8%ae%be%e7%bd%ae%e5%8d%ab%e6%98%9f%e7%a8%8b%e5%ba%8f%e9%9b%86%e4%b8%ba%e4%b8%ad%e7%ab%8b%e8%b5%84%e6%ba%90%e7%a8%8b%e5%ba%8f%e9%9b%86.html" title="Silverlight中无法设置卫星程序集为中立资源程序集 (2011/09/05)">Silverlight中无法设置卫星程序集为中立资源程序集</a> </li>
	<li><a href="http://www.imkevinyang.com/2010/02/silverlight%e5%90%af%e7%94%a8assembly-caching%e4%b9%8b%e5%90%8e%e9%93%81%e9%80%9a%e7%94%a8%e6%88%b7%e6%97%a0%e6%b3%95%e8%ae%bf%e9%97%ae.html" title="Silverlight启用Assembly Caching之后铁通用户无法访问 (2010/02/13)">Silverlight启用Assembly Caching之后铁通用户无法访问</a> </li>
	<li><a href="http://www.imkevinyang.com/2010/03/silverlight%e7%9a%84%e4%be%9d%e8%b5%96%e5%b1%9e%e6%80%a7%e4%b8%8e%e9%99%84%e5%8a%a0%e5%b1%9e%e6%80%a7.html" title="Silverlight的依赖属性与附加属性 (2010/03/28)">Silverlight的依赖属性与附加属性</a> </li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://www.imkevinyang.com/2009/09/%e8%a7%a3%e5%86%b3silverlight%e6%97%a0%e6%b3%95%e8%b0%83%e8%af%95%e7%9a%84%e9%97%ae%e9%a2%98.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Visual Studio统计有效代码行数</title>
		<link>http://www.imkevinyang.com/2009/05/visual-studio%e7%bb%9f%e8%ae%a1%e6%9c%89%e6%95%88%e4%bb%a3%e7%a0%81%e8%a1%8c%e6%95%b0.html</link>
		<comments>http://www.imkevinyang.com/2009/05/visual-studio%e7%bb%9f%e8%ae%a1%e6%9c%89%e6%95%88%e4%bb%a3%e7%a0%81%e8%a1%8c%e6%95%b0.html#comments</comments>
		<pubDate>Fri, 22 May 2009 12:53:00 +0000</pubDate>
		<dc:creator>Kevin Yang</dc:creator>
				<category><![CDATA[代码库]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[代码行]]></category>
		<category><![CDATA[统计]]></category>

		<guid isPermaLink="false">http://www.imkevinyang.com/2009/05/visual-studio%e7%bb%9f%e8%ae%a1%e6%9c%89%e6%95%88%e4%bb%a3%e7%a0%81%e8%a1%8c%e6%95%b0.html</guid>
		<description><![CDATA[<p>看网上有人专门做了一些小工具，用来统计代码行数。感觉不是很必要。因为Visual Studio中的搜索功能支持正则表达式（虽然语法比较诡异），我们完全可以通过正则表达式来遍历整个解决方案从而获得代码行数。</p>
<pre class="csharpcode">^:b*[^:b#/]+.*$</pre>
<p>需要注意：#开头和/开头或者空行都不计入代码量。</p>
<p>如果需要只统计代码文&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>看网上有人专门做了一些小工具，用来统计代码行数。感觉不是很必要。因为Visual Studio中的搜索功能支持正则表达式（虽然语法比较诡异），我们完全可以通过正则表达式来遍历整个解决方案从而获得代码行数。</p>
<pre class="csharpcode">^:b*[^:b#/]+.*$</pre>
<p>需要注意：#开头和/开头或者空行都不计入代码量。</p>
<p>如果需要只统计代码文件的代码量，可以按住Ctrl+Shift+F之后选择查找文件的类型。</p>

	标签：<a href="http://www.imkevinyang.com/tags/visual-studio" title="Visual Studio" rel="tag">Visual Studio</a>, <a href="http://www.imkevinyang.com/categories/techarticles/codebase" title="代码库" rel="tag">代码库</a>, <a href="http://www.imkevinyang.com/tags/%e4%bb%a3%e7%a0%81%e8%a1%8c" title="代码行" rel="tag">代码行</a>, <a href="http://www.imkevinyang.com/tags/%e7%bb%9f%e8%ae%a1" title="统计" rel="tag">统计</a><br />

	<h4 style="background-color:#3B3B3B;border-bottom:2px groove gray;color:#F2F2F2;margin-top:20px;padding:6px 6px 6px 15px;margin:20px 0px 0px 0px">你可能对下面的文章感兴趣</h4>
	<ul class="st-related-posts">
	<li><a href="http://www.imkevinyang.com/2009/09/visual-assist%e4%bb%a3%e7%a0%81%e6%8f%90%e7%a4%ba%e4%bd%bf%e7%94%a8%e7%9a%84%e5%ad%97%e7%ac%a6%e4%b8%b2%e6%a8%a1%e7%b3%8a%e5%8c%b9%e9%85%8d%e7%ae%97%e6%b3%95.html" title="Visual Assist代码提示使用的字符串模糊匹配算法 (2009/09/28)">Visual Assist代码提示使用的字符串模糊匹配算法</a> </li>
	<li><a href="http://www.imkevinyang.com/2010/09/visual-studio-2010%e9%87%8d%e5%91%bd%e5%90%8d%e9%87%8d%e6%9e%84%e6%97%b6%e5%87%ba%e7%8e%b0%e7%9a%84%e9%97%ae%e9%a2%98.html" title="Visual Studio 2010重命名重构时出现的问题 (2010/09/29)">Visual Studio 2010重命名重构时出现的问题</a> </li>
	<li><a href="http://www.imkevinyang.com/2009/09/visual-studio%e5%b0%8f%e8%b4%b4%e5%a3%ab%e5%8a%a0%e4%ba%86try-catch%e4%b9%9f%e8%83%bd%e8%87%aa%e5%8a%a8%e5%ae%9a%e4%bd%8d%e5%88%b0%e5%bc%82%e5%b8%b8%e4%bb%a3%e7%a0%81.html" title="Visual Studio小贴士&mdash;&mdash;加了Try-Catch也能自动定位到异常代码 (2009/09/18)">Visual Studio小贴士&mdash;&mdash;加了Try-Catch也能自动定位到异常代码</a> </li>
	<li><a href="http://www.imkevinyang.com/2010/07/visual-studio%e7%bc%96%e8%be%91%e5%99%a8%e4%b8%80%e6%ac%a1%e7%bc%a9%e8%bf%9b%e5%8f%8d%e7%bc%a9%e8%bf%9b4%e4%b8%aa%e7%a9%ba%e6%a0%bc.html" title="Visual Studio编辑器一次缩进/反缩进4个空格 (2010/07/04)">Visual Studio编辑器一次缩进/反缩进4个空格</a> </li>
	<li><a href="http://www.imkevinyang.com/2010/05/vs2010%e7%9a%84ui%e8%ae%be%e8%ae%a1%e5%a4%b1%e8%af%af.html" title="VS2010的UI设计失误 (2010/05/31)">VS2010的UI设计失误</a> </li>
	<li><a href="http://www.imkevinyang.com/2011/04/vs%e7%bc%96%e8%af%91%e6%97%b6%e8%87%aa%e5%8a%a8%e5%bc%95%e7%94%a8debugrelease%e7%89%88%e6%9c%ac%e7%9a%84dll.html" title="VS编译时自动引用Debug|Release版本的dll (2011/04/10)">VS编译时自动引用Debug|Release版本的dll</a> </li>
	<li><a href="http://www.imkevinyang.com/2010/02/%e4%bd%bf%e7%94%a8feedburner%e7%83%a7%e5%88%b6rss%e6%9c%80%e5%a5%bd%e7%a6%81%e7%94%a8itemlinkclicks%e7%bb%9f%e8%ae%a1.html" title="使用FeedBurner烧制RSS最好禁用ItemLinkClicks统计 (2010/02/15)">使用FeedBurner烧制RSS最好禁用ItemLinkClicks统计</a> </li>
	<li><a href="http://www.imkevinyang.com/2009/09/%e8%a7%a3%e5%86%b3silverlight%e6%97%a0%e6%b3%95%e8%b0%83%e8%af%95%e7%9a%84%e9%97%ae%e9%a2%98.html" title="解决Silverlight无法调试的问题 (2009/09/01)">解决Silverlight无法调试的问题</a> </li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://www.imkevinyang.com/2009/05/visual-studio%e7%bb%9f%e8%ae%a1%e6%9c%89%e6%95%88%e4%bb%a3%e7%a0%81%e8%a1%8c%e6%95%b0.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk: enhanced

Served from: www.imkevinyang.com @ 2012-02-08 18:04:10 -->
