对mscorlib引用感到好奇

6
我很好奇不同项目模板中的 mscorlib 引用。
当我创建 WPF 项目时,在引用文件夹中找不到 mscorlib 文件。我认为它是默认引用的。
当我创建 Silverlight 项目时,可以在文件夹中找到它。它链接到 Silverlight 框架。然后我尝试删除它,当然不能编译。然后我尝试重新将此程序集添加到引用中; 它无法添加并且无法再次编译。这很奇怪。
当我创建 MonoDroid 项目时,仍然可以找到 mscorlib 引用。但是在我删除此引用后,该项目仍然可以编译;但我不确定它是否运行良好。
有人知道是什么原因导致了这种行为吗?
谢谢, Howard
2个回答

8

为了避免大家去谷歌搜索,我在项目文件中缺少mscorlib,发现了CuiPengFei提出的确切方法,在这里:Microsoft Connect反馈的解决方法是由James Wightman于2009年12月9日下午2:52发布的:

As I said in the bug report, one workaround is to manually add the reference back into the project manually by editing the csproj file using (for example) notepad:

Find this section in the csproj file - obviously if you have different/additional references that's what you're looking for:

<ItemGroup>
 <Reference Include="System.Windows" />
 <Reference Include="system" />
 <Reference Include="System.Net" />
 <Reference Include="System.Xml" />
 <Reference Include="System.Windows.Browser" />
</ItemGroup>

Add a line for each of the missing references - in this case, mscorlib and System.Core - and your csproj file should now look something like this:

<ItemGroup>
 <Reference Include="mscorlib" />
 <Reference Include="System.Core" />
 <Reference Include="System.Windows" />
 <Reference Include="system" />
 <Reference Include="System.Net" />
 <Reference Include="System.Xml" />
 <Reference Include="System.Windows.Browser" />
</ItemGroup>

这应该是此处被接受的答案。我还想补充说明,在包含引用之后,您可能需要重新启动 Visual Studio 才能使其起作用。 - Bassie

6

这是一个已知的问题,无法在VS2010中修复。解决方法是编辑项目文件并手动重新添加引用。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接