dotnet / msbuild

The Microsoft Build Engine (MSBuild) is the build platform for .NET and Visual Studio.
https://docs.microsoft.com/visualstudio/msbuild/msbuild
MIT License
5.23k stars 1.35k forks source link

Linux Makefile project is not building from MSBuild (builds fine from Visual Studio) #5889

Open abelykh0 opened 3 years ago

abelykh0 commented 3 years ago

Issue Description

Linux Makefile project is not building from MSBuild (builds fine from Visual Studio)

Steps to Reproduce

In Visual Studio add a remote connection (Tools > Options > Cross Platform > Connection Manager > Add) In Visual Studio create a new "Makefile project" Rename it to "myprog"

Add file main.cpp like this

#include "stdio.h"
int main()
{
    printf("Hello");
    return 0;
}

Add file makefile (no extension) like this (note, it needs real tabs, not replaced by spaces, otherwise you'd get "*** missing separator")

src = $(wildcard *.cpp)
obj = $(src:.c=.o)
x64/Debug/myprog: $(obj)
    $(CC) -o $@ $^ $(LDFLAGS)
.PHONY: clean
clean:
    rm -f $(obj) x64/Debug

In Project Propertied > Remote Build specify: Build Command Line: make Outputs: $(Platform)/$(Configuration)/myprog

Make sure project builds from Visual Studio Delete bin and obj files from the project folder Open "Developer Command Prompt for VS 2019", change current folder to the project folder, run the following command :

msbuild /property:Configuration=Debug /property:Platform=x64 /verbosity:normal .\myprog.vcxproj

It fails. Note, if the folder obj\x64\Debug exists (even empty), it works.

Expected Behavior

Should build

Actual Behavior

You will get the following output:

>msbuild /property:Configuration=Debug /property:Platform=x64 /verbosity:normal .\myproj.vcxproj
Microsoft (R) Build Engine version 16.8.1+bd2ea1e3c for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

Build started 17/11/2020 10:33:00 AM.
Project "C:\myproj\myproj.vcxproj" on node 1 (default targets).
_ValidateSources:
  Validating sources
_CopySources:
  Copying sources remotely to '*****'
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Microsoft\VC\v160\Application Type\Linux\1.0\Lin
ux.Makefile.Targets(261,5): error : Exception occured while copying sources to remote machine - Could not find a part o
f the path 'C:\myproj\obj\x64\Debug\1085594582.Local_Remote_PathMapping.tlog'. [C
:\Users\andreyb\source\repos\Project4\Project4\myproj.vcxproj]
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Microsoft\VC\v160\Application Type\Linux\1.0\Lin
ux.Makefile.Targets(261,5): error : Could not find a part of the path 'C:\myproj\
obj\x64\Debug\1085594582.CopySourcesUpToDateFile.tlog'. [C:\myproj\myproj.vcxproj
]
Done Building Project "C:\myproj\myproj.vcxproj" (default targets) -- FAILED.

Build FAILED.

"C:\myproj\myproj.vcxproj" (default target) (1) ->
(_CopySources target) ->
  C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Microsoft\VC\v160\Application Type\Linux\1.0\L
inux.Makefile.Targets(261,5): error : Exception occured while copying sources to remote machine - Could not find a part
 of the path 'C:\myproj\obj\x64\Debug\1085594582.Local_Remote_PathMapping.tlog'.
[C:\myproj\myproj.vcxproj]
  C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Microsoft\VC\v160\Application Type\Linux\1.0\L
inux.Makefile.Targets(261,5): error : Could not find a part of the path 'C:\Users\andreyb\source\repos\Project4\Project
4\obj\x64\Debug\1085594582.CopySourcesUpToDateFile.tlog'. [C:\myproj\myproj.vcxpr
oj]

    0 Warning(s)
    2 Error(s)

Time Elapsed 00:00:01.87

Analysis

If I add the following workaround (modify project file), it starts to work:

  <Target Name="WorkaroundForMakefileIssue" BeforeTargets="_ConsolidateSourcesToCopy">
    <MakeDir Directories="obj\x64\$(Configuration)" />
  </Target>

Versions & Configurations

Microsoft (R) Build Engine version 16.8.1+bd2ea1e3c for .NET Framework Copyright (C) Microsoft Corporation. All rights reserved.

16.8.1.52902

abelykh0 commented 3 years ago

@BenVillalobos, do you have any update on this issue? ETA?

xXTurnerLP commented 2 years ago

This is a problem I had and still have, workaround is to kill MSBuild before each build (taskkill /f /im MSBuild.exe in cmd)

but i have a shit ton of other errors with nothing more than a stacktrace, msbuild is so fucking shit..

benvillalobos commented 1 year ago

The workaround here is the solution I'd expect. MSBuild doesn't control the Linux.Makefile.Targets file. I see it's installed under VS, is this on the cpp side of things? @yuehuang010

It looks like ConsolidateSourcesToCopy could do an existence check on the output directory if it doesn't exist.

yuehuang010 commented 1 year ago

@xXTurnerLP, to best reach the team, can you please create a ticket in DeveloperCommunity.