phmonte / Buildalyzer

A utility to perform design-time builds of .NET projects without having to think too hard about it.
MIT License
606 stars 95 forks source link

Cannot compile simpliest C++ project #136

Closed kscieslinski closed 4 years ago

kscieslinski commented 4 years ago

Hi,

Workspace I cannot compile even the simpliest C++ project using Buildalyzer. I'm working on updated Windows 10 with Visual Studio version 16.04. I've download the newest Buildalyzer package form NuGet.

Project structure

Solution test_compilation:
-->  project compiler (c#)
  \--> Program.cs
--> project to_compile(c++)
  \--> main.cpp

Where Program.cs from project compiler looks like:

class Program
{
    static void Main(string[] args)
    {
        StringWriter log = new StringWriter();
        AnalyzerManagerOptions options = new AnalyzerManagerOptions
        {
            LogWriter = log
        };

        AnalyzerManager manager = new AnalyzerManager(@"C:\Users\User\source\repos\tests\tests.sln", options);
        IProjectAnalyzer analyzer = manager.GetProject(@"C:\Users\User\source\repos\tests\res\res.vcxproj");
        analyzer.SetGlobalProperty("SolutionDir", @"C:\Users\User\source\repos\tests\");
        IAnalyzerResults results = analyzer.Build();
        Console.WriteLine(log.ToString());
    }
}

And main.cpp from to_compile project is:

int main() {
  std::cout << "Hello World" << std::endl;
}

Firstly I received an error about not being able to locate C:\Microsoft.cpp.default.props which I've solved manually by adding a VCTargetsPath environment variable: VCTargetsPath=C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\

But now I get new error:


Started process 4568: "dotnet" --info
.NET Core SDK (reflecting any global.json):
 Version:   3.1.101
 Commit:    b377529961
Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.18363
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\3.1.101\
Host (useful for support):
  Version: 3.1.1
  Commit:  a1388f194c
.NET Core SDKs installed:
  3.1.101 [C:\Program Files\dotnet\sdk]
.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download
Process 4568 exited with code 0

Started process 8540: "dotnet" "C:\Program Files\dotnet\sdk\3.1.101\MSBuild.dll" /noconsolelogger /restore /target:Clean;Build /property:ProvideCommandLineArgs="true";GenerateResourceMSBuildArchitecture="CurrentArchitecture";DesignTimeBuild="true";BuildProjectReferences="false";SkipCompilerExecution="true";DisableRarCache="true";AutoGenerateBindingRedirects="false";CopyBuildOutputToOutputDirectory="false";CopyOutputSymbolsToOutputDirectory="false";SkipCopyBuildProduct="true";AddModules="false";UseCommonOutputDirectory="true";GeneratePackageOnBuild="false";NonExistentFile="__NonExistentSubDir__\__NonExistentFile__";SolutionDir="C:\Users\User\source\repos\test_compilation\test_compilation.sln" /l:BuildalyzerLogger,"C:\Users\User\source\repos\test_compilation\compiler\bin\Debug\netcoreapp3.1\Buildalyzer.Logger.dll";988;False "C:\Users\User\source\repos\test_compilation\to_compile\to_compile.vcxproj"
Microsoft (R) Build Engine version 16.4.0+e901037fe for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
The "GetOutOfDateItems" task failed unexpectedly.
System.TypeLoadException: Could not load type 'Microsoft.Build.Utilities.CanonicalTrackedOutputFiles' from assembly 'Microsoft.Build.Utilities.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
   at Microsoft.Build.CPPTasks.GetOutOfDateItems.Execute()
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask)Process 8540 exited with code 1

C:\Users\User\source\repos\test_compilation\compiler\bin\Debug\netcoreapp3.1\compiler.exe (process 12080) exited with code 0.
To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops.
Press any key to close this window . . .

I believe the whole idea of Buildalyzer was to resolve those issues automatically and not having to set all those paths by hand (which is a great idea).

daveaglick commented 4 years ago

You're totally correct about the purpose of Buildalyzer being to remove all the boilerplate from triggering a compilation. Unfortunately only C# projects are in-scope for this project (VB and F# projects should mostly work as well, but they're not directly supported and I rely on community contributions for those).

C++ projects go through a different compiler (I.e., not Roslyn) and it's been over a decade since I've done any work in C++ so I don't know anything about that toolchain. Normally I'd consider a community contribution if anyone wanted to look into it, but I don't even feel comfortable supporting something that complex long-term for a new toolchain and language, so C++ projects are likely just plain out-of-scope for the foreseeable future.

Sorry!

kscieslinski commented 4 years ago

:( Anyway really neat idea with this project:) Good luck with further development:)

daveaglick commented 4 years ago

Thanks, and sorry I couldn’t be more help! I’ll keep my eyes open for something similar for C++ though and drop back in if I see anything.