【发布时间】:2013-06-21 09:16:43
【问题描述】:
根据此处的答案:Which, if any, recent Windows updates should I uninstall to revivify Silverlight or rectify other problems?,我卸载/重新安装了 Silverlight 并重新启动。但是,现在我得到一个编译错误,即:
“未找到导入的项目“C:\Program Files (x86)\MSBuild\Microsoft\Silverlight\v5.0\Microsoft.Silverlight.CSharp.targets”。确认声明中的路径是正确,并且该文件存在于磁盘上。”
它指向 *.csproj 文件中的这一行:
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Silverlight\$(SilverlightVersion)\Microsoft.Silverlight.CSharp.targets" />
我不明白这是在做什么,确切地说;如果从远处可以理解,我需要做什么来解决这个困境?
更新
当我尝试安装 Silverlight 4 工具时(如某些指示是/解决方案,例如Silverlight 4: Resolving Microsoft.Silverlight.CSharp.targets was not found?),我得到“安装要求:
必须先安装与 Silverlight Tools 4 语言版本匹配的 Visual Studio 2010 或 Visual Web Developer Express 2010 或 Visual Phone Developer Express 2010,然后才能继续安装 Silverlight Tools。 Silverlight 工具以其他语言提供,地址为http://go.microsoft.com/fwlink/?LinkId=177432。 "
我确实安装了 VS 2010 (SP1)。我什至还安装了用于 Web 的 VS Express (2012)!
更新 2
根据另一个提示,我还安装了 Silverlight 4 SDK,但现在尝试打开项目时,我得到,“您需要在打开 Silverlight 项目之前安装最新的 Silverlight Developer 运行时'布拉'。” 它让我(再次)安装 Silverlight 5。
我这样做了,但我重新启动了,并且...仍然收到相同的错误消息...
更新 3
我在csproj文件中替换了这一行:
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Silverlight\$(SilverlightVersion)\Microsoft.Silverlight.CSharp.targets" />
...用这个:
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
...我比以前走得更远,但我不知道最后的改变是否是必要的改变,或者上面列举的所有步骤是否都是必要的。除了暗影之外,很可能没人知道。
更新 4
实际上,只需添加该行(无需替换另一行),项目编译,但随后似乎失去了对Razor或其他东西的了解,因为它此 YSOD 失败:
Server Error in '/TLDReporter' Application.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0103: The name 'Helprs' does not exist in the current context
Source Error:
Line 493: <div class="inner" style="width: 300px;">
Line 494: <p id="portal_breadcrumbs" class="breadcrumb">
Line 495: @Helprs.Sitemap(ConfigurationManager.AppSettings["ApplicationHome"])
Line 496: </p>
Line 497: </div>
Source File: c:\Project\. . .\Shared\_Layout.cshtml Line: 495
更新 5
好吧,无论出于何种原因,地平线上出现的短暂希望只是短暂的海市蜃楼 - 在发布上一次更新后,同样的错误立即返回。
但是,一旦我替换了这个:
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Silverlight\$(SilverlightVersion)\Microsoft.Silverlight.CSharp.targets" />
...用这个:
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Silverlight\v4.0\Microsoft.Silverlight.CSharp.targets" />
...基于此:http://msdn.microsoft.com/en-us/library/ff921165(v=PandP.20).aspx
...我更进一步,但再次回到这个编译点:
@Helprs.Sitemap(ConfigurationManager.AppSettings["ApplicationHome"])
更新 6
所有这一切都很奇怪的是解决方案可以编译,但是当我运行它时,它会抛出一个声称是编译错误结果的 YSOD。为什么编译器会编译成功,但是当我去运行应用程序时,却突然停了下来,以一种不自然的尖锐声调尖叫着“编译错误”?
【问题讨论】:
-
我升级到VS2013后也遇到了同样的问题,但没有找到任何解决方案。我把它贴在stackoverflow.com/questions/20054544/…
-
+100 非常感谢您这篇非常详细的帖子。您的更新 5 在更新 VS 2015 后修复了我的 Silverlight 问题。我希望我能一次又一次地支持这篇文章。向你致敬!
-
@AnneLagang:我很高兴它有帮助!
标签: silverlight versioning importerror csproj