C# 未找到导入的项目“C:\Microsoft.CSharp.targets”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5694/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
The imported project "C:\Microsoft.CSharp.targets" was not found
提问by lomaxx
I got this error today when trying to open a Visual Studio 2008 projectin Visual Studio 2005:
我今天尝试在 Visual Studio 2005 中打开 Visual Studio 2008项目时遇到此错误:
The imported project "C:\Microsoft.CSharp.targets" was not found.
未找到导入的项目“C:\Microsoft.CSharp.targets”。
采纳答案by lomaxx
Open your csproj file in notepad (or notepad++) Find the line:
在记事本(或记事本++)中打开您的 csproj 文件,找到以下行:
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
and change it to
并将其更改为
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
回答by Oleg Sakharov
This link on MSDNalso helps a lot to understand the reason why it doesn't work. $(MSBuildToolsPath) is the path to Microsoft.Build.Engine v3.5 (inserted automatically in a project file when you create in VS2008). If you try to build your project for .Net 2.0, be sure that you changed this path to $(MSBuildBinPath) which is the path to Microsoft.Build.Engine v2.0.
MSDN 上的这个链接对于理解它不起作用的原因也很有帮助。$(MSBuildToolsPath) 是 Microsoft.Build.Engine v3.5 的路径(在 VS2008 中创建时自动插入到项目文件中)。如果您尝试为 .Net 2.0 构建项目,请确保将此路径更改为 $(MSBuildBinPath),即 Microsoft.Build.Engine v2.0 的路径。
回答by Andre Luus
ok so what if it say this: between the gt/lt signs
Import Project="$(MSBuildExtensionsPath)\Microsoft\Silverlight\v3.0\Microsoft.Silverlight.CSharp.targets" /
how do i fix the targets error?
好吧,如果它这么说呢:在 gt/lt 标志之间
导入项目="$(MSBuildExtensionsPath)\Microsoft\Silverlight\v3.0\Microsoft.Silverlight.CSharp.targets" /
我如何修复目标错误?
I also found that import string in a demo project (specifically "Build your own MVVM Framework" by Rob Eisenburg).
我还在演示项目中发现了导入字符串(特别是 Rob Eisenburg 的“构建您自己的 MVVM 框架”)。
If you replace that import with the one suggested by lomaxx VS2010 RTM reports that you need to install this.
如果您用 lomaxx VS2010 RTM 报告建议的导入替换该导入,您需要安装它。
回答by Peter
I got this after reinstalling Windows. Visual Studio was installed, and I could see the Silverlight project type in the New Project window, but opening one didn't work. The solution was simple: I had to install the Silverlight Developer runtime and/or the Microsoft Silverlight 4 Tools for Visual Studio. This may seem stupid, but I overlooked it because I thought it should work, as the Silverlight project type was available.
重新安装Windows后我得到了这个。Visual Studio 已安装,我可以在“新建项目”窗口中看到 Silverlight 项目类型,但打开一个不起作用。解决方案很简单:我必须安装 Silverlight Developer 运行时和/或 Microsoft Silverlight 4 Tools for Visual Studio。这可能看起来很愚蠢,但我忽略了它,因为我认为它应该可以工作,因为 Silverlight 项目类型可用。
回答by stack247
For errors with Microsoft.WebApplications.targets
, you can:
对于错误Microsoft.WebApplications.targets
,您可以:
- Install Visual Studio 2010 (or the same version as in development machine) in your TFS server.
- Copy the “
Microsoft.WebApplication.targets
” from development machine file to TFS build machine.
- 在您的 TFS 服务器中安装 Visual Studio 2010(或与开发机器中相同的版本)。
- 将“
Microsoft.WebApplication.targets
”从开发机器文件复制到 TFS 构建机器。
Here'sthe post.
这是帖子。
回答by appenthused
I used to have this following line in the csproj file:
我曾经在 csproj 文件中有以下这行:
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
After deleting this file, it works fine.
删除此文件后,它工作正常。
回答by Greg Gum
This error can also occur when opening a Silverlight project that was built in SL 4, while you have SL 5 installed.
在安装了 SL 5 的情况下打开在 SL 4 中构建的 Silverlight 项目时,也会发生此错误。
Here is an example error message: The imported project "C:\Program Files (x86)\MSBuild\Microsoft\Silverlight\v4.0\Microsoft.Silverlight.CSharp.targets" was not found.
以下是错误消息示例:未找到导入的项目“C:\Program Files (x86)\MSBuild\Microsoft\Silverlight\v4.0\Microsoft.Silverlight.CSharp.targets”。
Note the v4.0.
注意 v4.0。
To resolve, edit the project and find:
要解决,请编辑项目并找到:
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
And change it to v5.0.
并将其更改为 v5.0。
Then reload project and it will open (unless you do not have SL 5 installed).
然后重新加载项目,它将打开(除非您没有安装 SL 5)。
回答by Alf Moh
If you are to encounter the error that says Microsoft.CSharp.Core.targets not found
, these are the steps I took to correct mine:
如果您遇到说 的错误Microsoft.CSharp.Core.targets not found
,这些是我为纠正我的错误所采取的步骤:
Open any previous working projects folder and navigate to the link showed in the error, that is
Projects/(working project name)/packages/Microsoft.Net.Compilers.1.3.2/tools/
and search forMicrosoft.CSharp.Core.targets
file.Copy this file and put it in the non-working project
tools folder
(that is, navigating to the tools folder in the non-working project as shown above)Now close your project (if it was open) and reopen it.
打开任何以前的工作项目文件夹并导航到错误中显示的链接,即
Projects/(working project name)/packages/Microsoft.Net.Compilers.1.3.2/tools/
搜索Microsoft.CSharp.Core.targets
文件。复制这个文件,放到非工作项目中
tools folder
(即导航到非工作项目中的tools文件夹,如上图)现在关闭您的项目(如果它已打开)并重新打开它。
It should be working now.
它现在应该可以工作了。
Also, to make sure everything is working properly in your now open Visual Studio Project, Go to Tools > NuGetPackage Manager > Manage NuGet Packages For Solution
. Here, you might find an error that says, CodeAnalysis.dll is being used by another application.
此外,要确保在您现在打开的 Visual Studio 项目中一切正常,请转到Tools > NuGetPackage Manager > Manage NuGet Packages For Solution
. 在这里,您可能会发现一个错误,指出 CodeAnalysis.dll 正在被另一个应用程序使用。
Again, go to the tools folder
, find the specified file and delete it. Come back to Manage NuGet Packages For Solution
. You will find a link that will ask you to Reload, click it and everything gets re-installed.
再次,转到tools folder
,找到指定的文件并删除它。回到Manage NuGet Packages For Solution
. 您会找到一个链接,要求您重新加载,单击它并重新安装所有内容。
Your project should be working properly now.
您的项目现在应该可以正常工作了。
回答by Bharat
This is a global solution, not dependent on particular package or bin.
这是一个全局解决方案,不依赖于特定的包或 bin。
In my case, I removed Packagesfolder from my root directory.
就我而言,我从根目录中删除了Packages文件夹。
Maybe it happens because of your packages are there but compiler is not finding it's reference. so remove older packages first and add new packages.
也许这是因为你的包在那里,但编译器没有找到它的引用。所以首先删除旧包并添加新包。
Steps to Add new packages
添加新包的步骤
- First remove, packages folder (it will be near by or one step up to your current project folder).
- Then restart the project or solution.
- Now, Rebuild solution file.
- Project will get new references from nuGet package manager. And your issue has been resolved.
- 首先删除,包文件夹(它将靠近或一步到您当前的项目文件夹)。
- 然后重新启动项目或解决方案。
- 现在,重建解决方案文件。
- 项目将从 nuGet 包管理器获得新的引用。并且您的问题已经解决。
This is not proper solution, but I posted it here because I face same issue.
这不是正确的解决方案,但我在这里发布了它,因为我面临同样的问题。
In my case, I wasn't even able to open my solution in visual studio and didn't get any help with other SO answers.
就我而言,我什至无法在 Visual Studio 中打开我的解决方案,也没有得到其他 SO 答案的任何帮助。
回答by Ben
In my case, I opened my .csproj file in notepad and removed the following three lines. Worked like a charm:
就我而言,我在记事本中打开了我的 .csproj 文件并删除了以下三行。像魅力一样工作:
<Import Project="..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props" Condition="Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" />
<Import Project="..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props')" />
<Import Project="..\packages\Microsoft.Net.Compilers.1.3.2\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.1.3.2\build\Microsoft.Net.Compilers.props')" />