Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to get compilation #28

Closed
kentcb opened this issue Oct 31, 2017 · 14 comments
Closed

Unable to get compilation #28

kentcb opened this issue Oct 31, 2017 · 14 comments

Comments

@kentcb
Copy link

kentcb commented Oct 31, 2017

When calling GetCompilationAsync I am seeing TaskCanceledException for some projects. Digging in, I found that the build itself is failing:

var buildalyzerLogFactory = new BuildalyzerLogFactory(logSink);
var manager = new AnalyzerManager(initialPath, loggerFactory: buildalyzerLogFactory);
var solution = manager.GetWorkspace().CurrentSolution;

In this code, the final line triggers a build of the solution. Here is the full log output of my application run, which includes the Buildalyzer output interspersed with my own library's output.

Notice these points of interest:

  • All references seem to conflict...with themselves
  • The Xamarin.Forms project appears to create problems with respect to Xamarin.Forms.Build.Tasks.FixedCreateCSharpManifestResourceName
  • You can see the TaskCanceledException at the end. I get this when attempting to get the compilation for the Services.Connected project. Other projects (Utility, ViewModels, and Services) do successfully return a compilation (I have no idea if it's usable yet though)
@kentcb
Copy link
Author

kentcb commented Nov 4, 2017

Finally got a chance to return to this...

Hmm, I can very easily recreate the conflicting references problem, but it does not actually appear to be the reason for compilations failing in my real project. I've adapted my sample and attached it. You'll see it logs a whole bunch of problems, but still manages to create the compilation at the end of the process...

Are you able to repro this?

BuildalyzerRepro.zip

@kentcb
Copy link
Author

kentcb commented Nov 4, 2017

OK, this gets weirder... I just found that I can only repro the conflicting references problem if I first build the Target solution (in VS) and then run the repro. If I then delete the obj directories from the target output (not the bin directories), it clears up the references problem. However, these errors remain:

C:\Program Files\dotnet\sdk\2.0.2\Sdks\Microsoft.NET.Sdk\Sdk\Sdk.targets(41,3): error MSB4019: The imported project "C:\Program Files\dotnet\Microsoft.CSharp.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.

@kentcb
Copy link
Author

kentcb commented Nov 4, 2017

OK, WOW. If I simply git clean -xdf my target project before running PCLMock against it, now it works!

So the presence of binaries under obj in the target location is seriously screwing things up...

@daveaglick
Copy link
Collaborator

That's great intel. I wasn't able to reproduce when I tried a couple days ago - hopefully this gets me closer. My first thought it maybe is has something to do with the project.assets.json file that the SDK NuGet task sticks in the obj folder. That can screw up a build if it gets out of sync.

@kentcb
Copy link
Author

kentcb commented Nov 12, 2017

Hi @daveaglick - just wondering whether you managed to repro this?

@daveaglick
Copy link
Collaborator

I haven't had a ton of OSS time the last week or so - hoping things settle down a bit at work and I can get back to it this week.

@kentcb
Copy link
Author

kentcb commented Dec 22, 2017

Tried some things tonight:

  • running against a clean source tree (works, but there are still a disconcerting number of "errors" in the output)
  • running against a dirty source tree (fails)
  • deleting only the project.assets.json files from the dirty source tree and running again (works, but again has a very high number of "errors" in the output)

These are the errors I see when running against a clean source tree:

[PCLMock.CodeGeneration.Logging.BuildalyzerLogFactory]     C:\Program Files\dotnet\sdk\2.1.2\Sdks\Microsoft.NET.Sdk\Sdk\Sdk.targets(41,3): error MSB4019: The imported project "C:\Users\Kent\Repository\PCLMock\Src\PCLMock.CodeGeneration.Console\bin\Debug\netcoreapp2.0\Microsoft.CSharp.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.

And when running against a dirty tree without project.assets.json:

[PCLMock.CodeGeneration.Logging.BuildalyzerLogFactory]   C:\Users\Kent\.nuget\packages\xamarin.forms\2.5.0.91635\build\netstandard1.0\Xamarin.Forms.targets(55,3): error MSB4062: The "Xamarin.Forms.Build.Tasks.GetTasksAbi" task could not be loaded from the assembly C:\Users\Kent\.nuget\packages\xamarin.forms\2.5.0.91635\build\netstandard1.0\Xamarin.Forms.Build.Tasks.dll. Could not load file or assembly 'Microsoft.Build.Utilities.v4.0, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified. Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask.
[PCLMock.CodeGeneration.Logging.BuildalyzerLogFactory]     C:\Program Files\dotnet\sdk\2.1.2\Sdks\Microsoft.NET.Sdk\Sdk\Sdk.targets(41,3): error MSB4019: The imported project "C:\Users\Kent\Repository\PCLMock\Src\PCLMock.CodeGeneration.Console\bin\Debug\netcoreapp2.0\Microsoft.CSharp.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.

@kentcb
Copy link
Author

kentcb commented Dec 22, 2017

Another possible clue...

I tried checking what files were being reported by ProjectAnalyzer.GetSourceFiles in both cases (working and failing).

The failing case reports a hell of a lot more files. Here is the list from a working build and a failing build.

Not sure what this tells me yet, if anything. Think I'm done for now 😫

@curtisshipley
Copy link

I finally got some time to play with this, but didn't get very far. I grabbed the BuildalyzerRepro.zip. It seems to be looking for SampleTarget.sln which doesn't appear to be included. Is this something I should create?

If you could check your updated sample files in somewhere, that would be helpful.

@kentcb
Copy link
Author

kentcb commented Dec 24, 2017

@curtisshipley SampleTarget.sln is in there - it's under the Target directory.

@curtisshipley
Copy link

Ah, so it is. Thanks. Now I'm getting bitten by this:
dotnet/msbuild#2775

An unhandled exception of type 'Microsoft.Build.Exceptions.InvalidProjectFileException' occurred in System.Private.CoreLib.dll
Invalid static method invocation syntax: "[MSBuild]::IsRunningFromVisualStudio()". [MSBuild]::IsRunningFromVisualStudio Static method invocation should be of the form: $([FullTypeName]::Method()), e.g. $([System.IO.Path]::Combine(a, b)).

I'll see what I can do to get past it.

@kentcb
Copy link
Author

kentcb commented Dec 26, 2017

@curtisshipley if you didn't find it already, a workaround for the MSBuild problem is discussed in #32

@daveaglick
Copy link
Collaborator

Buildalyzer 1.0.0 was released to NuGet last night. Can you please try it out when you get the chance and let me know the status of this issue?

FYI - the Buildalyzer 1.0.0 API has changed significantly. Revised documentation is forthcoming, but I wanted to get the release out there ASAP. Hopefully you'll be able to figure out the differences, but if not the source code of the tests is a good place to look or wait until better docs are out next week.

@kentcb
Copy link
Author

kentcb commented Aug 1, 2018

I can no longer repro this particular issue with 1.0.0. Thanks!

@kentcb kentcb closed this as completed Aug 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants