none
msbuild error path is not of a legal form

    Question

  • Hi, I am trying to build libpng using visual studio. When building with vc90sp1 (Vs 2008), it works with no issues. I upgraded the project files to vc140 using visual studio and now when I build using msbuild, it gives me the 'path is not of a legal form' error:

    09:17:00.233 MSBuild    INFO         C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(253,5): error MSB4018: The "CL" task failed unexpectedly. [C:\libpng\build\obj\win64_vc140\libpng\build\projects\visualc140\libpng\libpng.vcxproj]
    09:17:00.234 MSBuild    INFO         C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(253,5): error MSB4018: System.TypeInitializationException: The type initializer for 'Microsoft.Build.Utilities.FileTracker' threw an exception. ---> System.ArgumentException: The path is not of a legal form. [C:\libpng\build\obj\win64_vc140\libpng\build\projects\visualc140\libpng\libpng.vcxproj]
    09:17:00.234 MSBuild    INFO         C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(253,5): error MSB4018:    at System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength, Boolean expandShortPaths) [C:\libpng\build\obj\win64_vc140\libpng\build\projects\visualc140\libpng\libpng.vcxproj]
    09:17:00.234 MSBuild    INFO         C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(253,5): error MSB4018:    at System.IO.Path.GetPathRoot(String path) [C:\libpng\build\obj\win64_vc140\libpng\build\projects\visualc140\libpng\libpng.vcxproj]
    09:17:00.234 MSBuild    INFO         C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(253,5): error MSB4018:    at Microsoft.Build.Utilities.FileTracker..cctor() [C:\libpng\build\obj\win64_vc140\libpng\build\projects\visualc140\libpng\libpng.vcxproj]
    09:17:00.234 MSBuild    INFO         C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(253,5): error MSB4018:    --- End of inner exception stack trace --- [C:\libpng\build\obj\win64_vc140\libpng\build\projects\visualc140\libpng\libpng.vcxproj]
    09:17:00.234 MSBuild    INFO         C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(253,5): error MSB4018:    at Microsoft.Build.CPPTasks.CL.ComputeOutOfDateSources() [C:\libpng\build\obj\win64_vc140\libpng\build\projects\visualc140\libpng\libpng.vcxproj]
    09:17:00.234 MSBuild    INFO         C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(253,5): error MSB4018:    at Microsoft.Build.Utilities.ToolTask.Execute() [C:\libpng\build\obj\win64_vc140\libpng\build\projects\visualc140\libpng\libpng.vcxproj]
    09:17:00.234 MSBuild    INFO         C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(253,5): error MSB4018:    at Microsoft.Build.CPPTasks.TrackedVCToolTask.Execute() [C:\libpng\build\obj\win64_vc140\libpng\build\projects\visualc140\libpng\libpng.vcxproj]
    09:17:00.234 MSBuild    INFO         C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(253,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [C:\libpng\build\obj\win64_vc140\libpng\build\projects\visualc140\libpng\libpng.vcxproj]
    09:17:00.234 MSBuild    INFO         C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(253,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext() [C:\libpng\build\obj\win64_vc140\libpng\build\projects\visualc140\libpng\libpng.vcxproj]
    09:17:00.234 MSBuild    INFO         Done Building Project "C:\libpng\build\obj\win64_vc140\libpng\build\projects\visualc140\libpng\libpng.vcxproj" (default targets) -- FAILED.
    09:17:00.235 MSBuild    INFO         Done Building Project "C:\libpng\build\obj\win64_vc140\libpng\build\projects\visualc140\libpng\libpng.vcxproj.metaproj" (default targets) -- FAILED.
    09:17:00.268 MSBuild    INFO         Done Building Project "C:\libpng\build\obj\win64_vc140\libpng\build\projects\visualc140\vstudio.sln" (default targets) -- FAILED.

    I have no clue how to debug this and don;t even know which path it is talking about when it says 'path is not of a legal form'. There is very limited help online as well. Would appreciate if you can help me find the solution. I need this asap since this is blocking my current work. Thanks in advance

    Monday, March 5, 2018 7:27 PM

All replies

  • Hitoast12,

    Thanks for posting here.

    According to the error log, it seems you are using the old MSBuild which from the .NET framework to build your project.

    Starting with Visual Studio 2013, the 2013 version of MSBuild will ship as a part of Visual Studio instead of the .NET Framework.

    https://blogs.msdn.microsoft.com/visualstudio/2013/07/24/msbuild-is-now-part-of-visual-studio/

    So, when you upgraded the project files to vc140 using msbuild, you should use the MSBuild from:

    C:\Program Files (x86)\MSBuild\14.0\Bin

    Hope this helps.


    MSDN Community Support Please remember to click Mark as Answer. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Tuesday, March 6, 2018 5:42 AM
  • Hi Leo,
    Thanks for the reply. But I am using the latest msbuild already from the same location you suggested: C:\Program Files (x86)\MSBuild\14.0\Bin
    So I did further analysis and looks like if I run directly on the command line it works. The issue happens when I call msbuild from a python subprocess. I am passing all the necessary environment variables to the subprocess. So what can be the issue?

    Tuesday, March 6, 2018 5:45 PM
  • @toast12, since your project is worked fine on the command line directly, so this issue should be related to how to call the correct MSBuild from a python sub process, it seems it used the old version MSBuild:

    C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140

    How did you call MSBuild from a python sub process? Have you specify the MSBuild path in the python subprocess?


    MSDN Community Support Please remember to click &quot;Mark as Answer&quot; the responses that resolved your issue, and to click &quot;Unmark as Answer&quot; if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, March 7, 2018 9:41 AM
  • Thank you Leo. I see your point now and think you might be correct that the MSBUILD is not correctly picked from python subprocess. When I run msbuild from my python script, it uses the correct msbuild but from inside the subprocess somehow it changes. Any way I can tell the subprocess to pick my version of msbuild? Any msbuild property? I am already using /useenv so I am not sure why it gets changed from inside the project
    Wednesday, March 7, 2018 10:26 PM
  • @toast12, you are always welcome. I am glad to know we have found the reason and solution on MSBuild but not for python subprocess. Sorry, I'm not familiar with Python, so I could not give a directly solution about how to uses the correct msbuild from inside the subprocess. As I suggest, you can open a new thread with the latter issue on python forum or on stackoverflow with python tag. More community members and MVP on that forum may further look at your issue and provide more suggestions.

    Besides, since this forum is bout MSBuild, I could only give you solution on MSBuild, if above answer resolve your question on MSBuild, you can mark it as answer, This can be beneficial to other community members reading this thread and we could close this thread.

    If you have some MSBuild questions, please feel free to contact us. We will try our best to give you a solution.


    MSDN Community Support Please remember to click &quot;Mark as Answer&quot; the responses that resolved your issue, and to click &quot;Unmark as Answer&quot; if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, March 9, 2018 8:19 AM
  • Hi Leo, I am not sure if we can definitively say that the reason you suggested is the correct answer. I tried everything and python subprocess seems to be getting all the environments set correct. So this might be either a visual studio issue or the issue with the project file contents. Till this resolved, please let this bug be open. I have nothing substantial that suggests the root cause. Thanks
    Monday, March 12, 2018 7:22 PM
  • Hi Leo, I did further analysis. Doesn't look like anything is wrong as far as the python subprocess call is concerned. My vcxproj project file uses this line:

    <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />

    I checked VCTargetsPath using HKEY_LOCAL_MACHINE and it seems to be pointing to

    C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140

    I think that is where the path is coming from. I compared with one of our different working projects that builds on vc140 and it has no build issues there. So I think, overall our direction was not completely correct. The problem lies elsewhere. And I am back to square one!

    Monday, March 12, 2018 9:14 PM
  • Hi Leo, any suggestions?
    Wednesday, March 14, 2018 5:42 AM
  • Hi toast12, sorry for late reply, I think you are right, overall our direction was not completely correct. So I return to the origin "The path is not of a legal form", but I create the same path for a C++ project, I works fine, so I not sure if this path is not supported by libpng. Since I am not familiar with libpng, I don know if this path is a legal form. What I can suggest is that you can try to move that project to the root directory C:\, or you can try to create a new libpng project in that path with Visual Studio 2015, check if it also have the same error.

    MSDN Community Support Please remember to click &quot;Mark as Answer&quot; the responses that resolved your issue, and to click &quot;Unmark as Answer&quot; if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, March 14, 2018 6:44 AM
  • Hi Leo, I don't think path to the project is an issue because it works when I run msbuild directly on the command line

    Is there a way I can reach out to MSFT visual studio development team, preferably in US? This is a very intriguing issue and updating here on the forum and waiting for responses is quite time consuming. Thanks

    Thursday, March 15, 2018 2:18 AM
  • @toast12, you can visit this link to see the various support options that are available to better meet your needs:  http://support.microsoft.com/default.aspx?id=fh;en-us;offerprophone. Thanks for your understanding. 

    MSDN Community Support Please remember to click &quot;Mark as Answer&quot; the responses that resolved your issue, and to click &quot;Unmark as Answer&quot; if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, March 15, 2018 4:42 AM
  • I am too hitting with the same issue. If the issue is resolved, @toast12. can you kindly post the solution to the issue. Thanks
    Monday, June 11, 2018 7:31 PM