phmonte / Buildalyzer

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

Zero results returned even though build succeeds #80

Closed patearl closed 2 years ago

patearl commented 6 years ago

This is the code that runs:

            StringWriter log = new StringWriter();
            AnalyzerManagerOptions options = new AnalyzerManagerOptions();
            options.LogWriter = log;
            var analyzerManager = new AnalyzerManager(options);
            var projectAnalyzer = analyzerManager.GetProject(projectFile);
            var environmentOptions = new EnvironmentOptions();
            // Set a property that tells MSBuild to skip the model generation task so we don't run into infinite recursion
            environmentOptions.GlobalProperties["RunModellerGenerator"] = "false";
            var environment = projectAnalyzer.EnvironmentFactory.GetBuildEnvironment("net461", environmentOptions);
            var analyzerResults = projectAnalyzer.Build(environment);

            if (analyzerResults == null)
                throw BuildalyzerError("Buildalzyer results were null", log);

            if (!analyzerResults.Any())
                throw BuildalyzerError("Buildalyzer returned zero results", log);

The problem is that analyzerResults is empty (not null).

After removing the two logging things, this is the command that it runs:

    C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\bin\msbuild.exe" /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";RunModellerGenerator="false";NonExistentFile="__NonExistentSubDir__\__NonExistentFile__";ResolveNuGetPackages="true";SolutionDir="T:\buildAgent\work\10ea60c316b45bcf\Source\Pleasant.Wpf.Data.Tests" "T:\buildAgent\work\10ea60c316b45bcf\Source\Pleasant.Wpf.Data.Tests\Pleasant.Wpf.Data.Tests.csproj"

The build output from that command is attached in output.txt.

I imagine there is some sort of failure reading the output somehow since it looks like the build is doing what it is supposed to.

output.txt

daveaglick commented 6 years ago

Can you please attach or paste the content of log from the code above after calling projectAnalyzer.Build(environment) - that should contain the MSBuild output as well as information about the MSBuild exit code or any other problems encountered during execution.

Let me know if you see an error along the lines of MSBUILD : error MSB1021: Cannot create an instance of the logger. Could not load file or assembly 'MsBuildPipeLogger.Logger, Version=1.1.2.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified. That suggests the MsBuildPipeLogger package wasn't correctly installed or available.

PleasantD commented 6 years ago

This is what we see from the log

=================== BUILD OUTPUT =====================

Started process 2292: "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\bin\msbuild.exe"  /noconsolelogger /target:Restore /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";RunModellerGenerator="false";NonExistentFile="__NonExistentSubDir__\__NonExistentFile__";ResolveNuGetPackages="true";SolutionDir="T:\w\1ad69c20e141098a\Source\Pleasant.VirtualFileSystem" /l:BuildalyzerLogger,"C:\USERS\MRBUILD\.NUGET\PACKAGES\PLEASANTMODELLER.GENERATOR\5.1.25\BUILD\Buildalyzer.Logger.dll";2844;False "T:\w\1ad69c20e141098a\Source\Pleasant.VirtualFileSystem\Pleasant.VirtualFileSystem.csproj"
Microsoft (R) Build Engine version 15.7.179.6572 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

Process 2292 exited with code 0

Started process 3724: "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\bin\msbuild.exe"  /noconsolelogger /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";RunModellerGenerator="false";NonExistentFile="__NonExistentSubDir__\__NonExistentFile__";ResolveNuGetPackages="true";SolutionDir="T:\w\1ad69c20e141098a\Source\Pleasant.VirtualFileSystem" /l:BuildalyzerLogger,"C:\USERS\MRBUILD\.NUGET\PACKAGES\PLEASANTMODELLER.GENERATOR\5.1.25\BUILD\Buildalyzer.Logger.dll";2904;False "T:\w\1ad69c20e141098a\Source\Pleasant.VirtualFileSystem\Pleasant.VirtualFileSystem.csproj"
Microsoft (R) Build Engine version 15.7.179.6572 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

Process 3724 exited with code 0

======================================================
PleasantD commented 6 years ago

I work with @patearl

A little more detail of what we are doing and what is going wrong:

We have an MSBuild task that is generating some code for us. Part of that code examines the project file and loads embedded resources from referenced DLLs. We are attempting to run Buildalyzer inside the custom task to give us the list of referenced DLLs that used to be present in the csproj structure directly.

This works for us on our development machines from within visual studio. It fails when we try to run it from the MSBuild script we use for CI.

daveaglick commented 5 years ago

Hi folks, sorry for the really long silence!

Version 2.3.0 was just released and it includes a much better mechanism for finding the most recent MSBuild. I'm wondering if the resolution of MSBuild was different between development and CI. If you get a chance and this is still an issue, could you try version 2.3.0 and report back. If that doesn't help the next step will be to turn on some more aggressive logging and output a binlog.

daveaglick commented 2 years ago

Since this is pretty old and there have been ongoing improvements, I'm going to assume this issue is either resolved or no longer relevant. Please comment or open a new issue if that's incorrect and you're still having trouble.