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

  • Question

  • 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.
    Monday, August 11, 2008 4:13 PM

Answers

  • 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
    • Marked as answer by Feng Chen Thursday, August 14, 2008 9:46 AM
    Monday, August 11, 2008 6:38 PM

All replies

  • 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
    • Marked as answer by Feng Chen Thursday, August 14, 2008 9:46 AM
    Monday, August 11, 2008 6:38 PM
  • 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!
    Tuesday, August 19, 2008 10:45 AM
  • 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
    Tuesday, August 19, 2008 10:12 PM
  • 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.
    Wednesday, August 20, 2008 7:29 AM
  • 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?
    Tuesday, June 16, 2009 4:48 PM
  • 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.
    Friday, August 7, 2009 8:04 AM
  • You should use msbuild executable that is shipped with .net 3.5 and not with 2.0 version.
    Friday, August 7, 2009 8:18 PM
  • 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!
    Thursday, August 20, 2009 1:42 AM
  • 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" />
    • Proposed as answer by Dhirendra Patil Thursday, January 14, 2010 12:24 PM
    Wednesday, December 2, 2009 10:16 PM
  • Yes. I fix it. Thank you very much !
    I saw, I came , I conquered!
    Sunday, December 6, 2009 3:22 AM
  • Thanks!

    that solved that issue 


    • Edited by Pan Zhang Wednesday, March 5, 2014 3:58 AM remove Advs
    Friday, June 11, 2010 4:22 PM
  • 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

    Saturday, September 3, 2011 6:11 PM
  • 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="" />

     

     

    Tuesday, October 11, 2011 1:08 PM
  • Yes, Its worked for me .Thanks
    Friday, September 7, 2012 9:33 AM
  • 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.
    Thursday, May 5, 2016 12:46 AM
  • 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.

    Friday, July 15, 2016 7:47 PM