none
Error MSB4019: The imported project "C:\Microsoft.CSharp.targets" was not found. RRS feed

  • 问题

  • Hello,

    Here is my code:
        static void Main(string[] args)  
        {  
            // Instantiate a new Engine object  
            Engine engine = new Engine(@"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\");  
            Project project = new Project(engine);  
     
            try 
            {  
                project.Load(@"C:\Projects\WindowsFormsApplication1\WindowsFormsApplication1\WindowsFormsApplication1.csproj");           
                Console.WriteLine("Success!");  
            }  
            catch(Exception ex)  
            {  
                // The imported project "E:\Microsoft.CSharp.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.  E:\Projects\WindowsFormsApplication1\WindowsFormsApplication1\WindowsFormsApplication1.csproj  
                Console.WriteLine("Failed: " + ex.Message);  
            }  
        }  
     
    WindowsFormsApplication1.csproj is a Windows Forms VS2008 project that I created by the wizard. When I run my code I got en exception:
    "C:\Projects\WindowsFormsApplication1\WindowsFormsApplication1\WindowsFormsApplication1.csproj(78,11): error MSB4019: The imported project "C:\Microsoft.CSharp.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk."

    Here is a line of code from WindowsFormsApplication1.csproj: 
      <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

    Could you advice how to resolve problem? That code works fine with VS2005 projects.
    2008年8月11日 16:13

答案

  • Your error indicates that MSBuildToolsPath is blank, that's why it's trying to load from c:\.

    One error I see is that you're loading .NET 2.0 but have created a project in VS 2008. Trying changing the engine path to the following and tell me if you get the same problem:

    C:\WINDOWS\Microsoft.NET\Framework\v3.5.20223\
    KodefuGuru.com - Life Student of the Kodefu Arts
    • 已标记为答案 Feng Chen 2008年8月14日 9:46
    2008年8月11日 18:38

全部回复

  • Your error indicates that MSBuildToolsPath is blank, that's why it's trying to load from c:\.

    One error I see is that you're loading .NET 2.0 but have created a project in VS 2008. Trying changing the engine path to the following and tell me if you get the same problem:

    C:\WINDOWS\Microsoft.NET\Framework\v3.5.20223\
    KodefuGuru.com - Life Student of the Kodefu Arts
    • 已标记为答案 Feng Chen 2008年8月14日 9:46
    2008年8月11日 18:38
  • Thank you for the answer.
    I had a problem because I tried to open VS2008 project when referencing Microsoft.Build.Engine v2.0! After changing that reference on new one (v3.5) everything works. Thanks anyway!
    2008年8月19日 10:45
  • Was the answer I gave correct or was it something else? I think it's important in case someone with the same problem finds this post.


    KodefuGuru.com - Life Student of the Kodefu Arts
    2008年8月19日 22:12
  • Ok, changing engine path did not fix the problem at all.
    Only after I removed reference assembly Microsoft.Build.Engine v2.0 and added reference Microsoft.Build.Engine v3.5 it worked.
    2008年8月20日 7:29
  • Ok, changing engine path did not fix the problem at all.
    Only after I removed reference assembly Microsoft.Build.Engine v2.0 and added reference Microsoft.Build.Engine v3.5 it worked.
    I have the same issue. I'm confused where from the reference was removed and added?
    2009年6月16日 16:48
  • Ok, changing engine path did not fix the problem at all.
    Only after I removed reference assembly Microsoft.Build.Engine v2.0 and added reference Microsoft.Build.Engine v3.5 it worked.
    Yes, I have met the same problem. And I want to know how to removed reference assembly v 2.0 and add reference v3.5.

    Thank you very much.
    2009年8月7日 8:04
  • You should use msbuild executable that is shipped with .net 3.5 and not with 2.0 version.
    2009年8月7日 20:18
  • I find how to uninstall the .Net Framework 2.0 completely.

    you  can use this tool released by Microsoft.

    Microsoft .NET Framework 卸载清理工具 2.0.0.4
    用于 Microsoft .NET Framework 1.0、Microsoft .NET Framework 1.1、Microsoft Visual Studio .NET 2002 和 Microsoft Visual Studio .NET 2003 的卸载清理工具
    http://download.pchome.net/system/uninstall/77203.html


    I saw, I came , I conquered!
    2009年8月20日 1:42
  • I had the same problem.  I fixed it by manually editing my .csproj file and changing
      <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
      to
      <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
    2009年12月2日 22:16
  • Yes. I fix it. Thank you very much !
    I saw, I came , I conquered!
    2009年12月6日 3:22
  • Thanks!

    that solved that issue 


    • 已编辑 Pan Zhang 2014年3月5日 3:58 remove Advs
    2010年6月11日 16:22
  • Just edited the last line of the project (.csproj) file 

      <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />

    to

      <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v9.0\WebApplications\Microsoft.WebApplication.targets" />

     

    as I am using Visual Studio 2008

    2011年9月3日 18:11
  • Hi i have changed V8.0 path for Visual Studio 2005 and works

      <Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v8.0\WebApplications\Microsoft.WebApplication.targets" Condition="" />

     

     

    2011年10月11日 13:08
  • Yes, Its worked for me .Thanks
    2012年9月7日 9:33
  • I had a similar issue opening a VS2008 Compact Framework solution that was working the previous time I opened it about a month before. I had upgraded from Windows 8 to Windows 10 in the interim. The upgrade had somehow removed my 3.5 Compact Framework files. Luckily, the Windows 10 upgrade creates a backup folder for the "Windows"  folder.  I copied the old CF files back into the new Windows folder and that fixed it.
    2016年5月5日 0:46
  • I did exactly the same thing you did David Isackson and that corrected the issue. I received the error after upgrading from 7 to 10.

    2016年7月15日 19:47