The imported project “C:\Microsoft.CSharp.targets”

2019-01-08 09:25发布

I got this error today when trying to open a Visual Studio 2008 project in Visual Studio 2005:

The imported project "C:\Microsoft.CSharp.targets" was not found.

14条回答
Juvenile、少年°
2楼-- · 2019-01-08 10:18

If you are to encounter the error that says Microsoft.CSharp.Core.targets not found, these are the steps I took to correct mine. 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 for Microsoft.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. 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. 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. Your project should be working properly now.

查看更多
放我归山
3楼-- · 2019-01-08 10:19

In my case, I opened my .csproj file in notepad and removed the following three lines. Worked like a charm:

<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')" />
查看更多
混吃等死
4楼-- · 2019-01-08 10:22

This error can also occur when opening a Silverlight project that was built in SL 4, while you have SL 5 installed.

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.

Note the v4.0.

To resolve, edit the project and find:

<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>

And change it to v5.0.

Then reload project and it will open (unless you do not have SL 5 installed).

查看更多
可以哭但决不认输i
5楼-- · 2019-01-08 10:23

I deleted the obj folder and then the project loaded as expected.

查看更多
Ridiculous、
6楼-- · 2019-01-08 10:26

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?

I also found that import string in a demo project (specifically "Build your own MVVM Framework" by Rob Eisenburg).

If you replace that import with the one suggested by lomaxx VS2010 RTM reports that you need to install this.

查看更多
smile是对你的礼貌
7楼-- · 2019-01-08 10:27

For me the issue was that the path of the project contained %20 characters, because git added those instead of spaces when the repository was cloned. Another problem might be if the path to a package is too long.

查看更多
登录 后发表回答