dotnet / android

.NET for Android provides open-source bindings of the Android SDK for use with .NET managed languages such as C#
MIT License
1.93k stars 529 forks source link

MSBuild process doesn't wait for resources generation in Restore target #6534

Open MihaMarkic opened 2 years ago

MihaMarkic commented 2 years ago

Steps to Reproduce

My scenario is a solution consisting of a .NETStandard 2 project, Android library with custom Android resources and Android application. No bin or obj directories exist (this is important).

  1. Invoke MSBuild on frontend project from command line with Targets Restore and Build

Expected Behavior

Project should compile.

Actual Behavior

Build fails when compiling for first time complaining about missing resources (error APT2260). Next compilation works assuming bin and obj directories aren't deleted in between. Now, if I do first Restore, wait for a second or two and then Build, it works. If there is no pause between the two steps, then it fails. I'm assuming Restore target doesn't wait for everything it does - or there is a caching issue on my computer. Is it possible that the cause is the former?

Version Information

Microsoft Visual Studio Community 2022 Version 17.0.1 VisualStudio.17.Release/17.0.1+31912.275 Microsoft .NET Framework Version 4.8.04084

Installed Version: Community

.NET Core Debugging with WSL 1.0 .NET Core Debugging with WSL

ASP.NET and Web Tools 2019 17.0.789.48259 ASP.NET and Web Tools 2019

ASP.NET Web Frameworks and Tools 2019 17.0.789.48259 For additional information, visit https://www.asp.net/

Azure App Service Tools v3.0.0 17.0.789.48259 Azure App Service Tools v3.0.0

Azure Functions and Web Jobs Tools 17.0.789.48259 Azure Functions and Web Jobs Tools

C# Tools 4.0.1-1.21561.4+add472bbed002fcea9232e89793d0762cc71c5cf C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Cake for Visual Studio 2022 0.1.1.0 Adds support for the Cake build tool in Visual Studio 2022. Includes support for the Task Runner Explorer, new templates and bootstrapping important Cake files.

CodeRush for Roslyn 21.2.4.0 DevExpress CodeRush for Roslyn package.

CodeRush for Roslyn Tool Windows 21.2.4.0 DevExpress CodeRush for Roslyn Tool Windows package.

Common Azure Tools 1.10 Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

CreateLayoutWizard 1.0 Create layout wizard.

DevExpress Reporting Extension 1.4 A Visual Studio extension that invokes the Report Designer editor for report definition VSREPX files.

DevExpress Reporting Tools Extension 1.0 Extends Visual Studio with tools required for the Report Designer editor.

DevExpress.DeploymentTool 1.0 A useful tool for deploying DevExpress assemblies.

DevExpress.Win.LayoutAssistant Extension 1.0 DevExpress.Win.LayoutAssistant Visual Studio Extension Detailed Info

Extensibility Message Bus 1.2.6 (master@34d6af2) Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration.

Microsoft JVM Debugger 1.0 Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Microsoft Library Manager 2.1.134+45632ee938.RR Install client-side libraries easily to any web project

Microsoft MI-Based Debugger 1.0 Provides support for connecting Visual Studio to MI compatible debuggers

Microsoft Visual Studio Tools for Containers 1.2 Develop, run, validate your ASP.NET Core applications in the target environment. F5 your application directly into a container with debugging, or CTRL + F5 to edit & refresh your app without having to rebuild the container.

Mono Debugging for Visual Studio 17.0.11 (54f19d2) Support for debugging Mono processes with Visual Studio.

NCrunch
Continuous Testing Tool for .NET Copyright � 2010-2021 Remco Software Ltd

NuGet Package Manager 6.0.0 NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

ProjectServicesPackage Extension 1.0 ProjectServicesPackage Visual Studio Extension Detailed Info

Razor (ASP.NET Core) 17.0.0.2152201+3319c75f898522ff4dc9cf0c70035c284264a1de Provides languages services for ASP.NET Core Razor.

SQL Server Data Tools 17.0.62110.20190 Microsoft SQL Server Data Tools

TypeScript Tools 17.0.1001.2002 TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools 4.0.1-1.21561.4+add472bbed002fcea9232e89793d0762cc71c5cf Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools 17.0.0-beta.21522.2+6d626ff0752a77d339f609b4d361787dc9ca93a5 Microsoft Visual F# Tools

Visual Studio Code Debug Adapter Host Package 1.0 Interop layer for hosting Visual Studio Code debug adapters in Visual Studio

Visual Studio Container Tools Extensions 1.0 View, manage, and diagnose containers within Visual Studio.

Visual Studio IntelliCode 2.2 AI-assisted development for Visual Studio.

Visual Studio Tools for Containers 1.0 Visual Studio Tools for Containers

VisualStudio.DeviceLog 1.0 Information about my package

VisualStudio.Foo 1.0 Information about my package

VisualStudio.Mac 1.0 Mac Extension for Visual Studio

WiX Toolset Visual Studio Extension 1.0.0.12 WiX Toolset Visual Studio Extension version 1.0.0.12 Copyright (c) .NET Foundation and contributors. All rights reserved.

Xamarin 17.0.0.341 (d17-0@ac52790) Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer 17.0.0.182 (remotes/origin/d17-0@ea204898d) Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin Templates 17.0.17 (9e779b0) Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.

Xamarin.Android SDK 12.1.0.5 (d17-0/6b0e6b2) Xamarin.Android Reference Assemblies and MSBuild support. Mono: c633fe9 Java.Interop: xamarin/java.interop/d17-0@febb1367 ProGuard: Guardsquare/proguard/v7.0.1@912d149 SQLite: xamarin/sqlite/3.36.0@a575761 Xamarin.Android Tools: xamarin/xamarin-android-tools/d17-0@a5194e9

Xamarin.iOS and Xamarin.Mac SDK 15.2.0.17 (738fde344) Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.

Log File

dellis1972 commented 2 years ago

@MihaMarkic

Are you using msbuild MyAndordProj.csproj /restore /t:Build ? This works much better than using "/t:Restore;Build"

dellis1972 commented 2 years ago

It might be that when using "/t:Restore;Build" the targets are both run in parallel, which might explain why it works then you use then on their own.

I would use the /restore option rather than calling /t:Restore

MihaMarkic commented 2 years ago

@dellis1972 I was using the later /t:Restore;Build. But even if I use first /t:Restore and then /t:Build it won't work unless there is some time in between.

dellis1972 commented 2 years ago

@MihaMarkic I always use msbuild MyAndordProj.csproj /restore /t:Build and have never had any issues with missing packages.

dellis1972 commented 2 years ago

Its possible they changed something in the NuGet targets maybe 🤷 .

MihaMarkic commented 2 years ago

@dellis1972 But are you using it on clean build? I mean no bin and obj directories present? I didn't notice it before because I usually first develop in VS and here and there fire build process from command line.

jonathanpeppers commented 2 years ago

@MihaMarkic if this still fails, maybe send us the msbuild.binlog file this command generates:

> msbuild YourProject.csproj /restore /bl /t:Rebuild

You can also try git clean -dxf or something instead of Rebuild.

MihaMarkic commented 2 years ago

@jonathanpeppers yea, still fails. How can I send you the binlog?

dellis1972 commented 2 years ago

@MihaMarkic the /bl command will generate a msbuild.binlog file, which you can zip up and attach to this issue.

MihaMarkic commented 2 years ago

Dang, I tried to repro it in a sample but it is inconsistent - even the original project sometime works. Can I send you the binlog privately since it's a commercial project?

dellis1972 commented 2 years ago

You can , both @jonathanpeppers and I have our email addresses in our Profiles.

MihaMarkic commented 2 years ago

FYI sent yesterday

dellis1972 commented 2 years ago

Yup I saw it. I had a quick look and it seems that the _ResolveLibraryProjectImports target is being skipped during a ReBuild. Because we see this

obj\Stage\110\libraryprojectimports.cache does not exist. No Project Library Imports found 

Which means none of the resource dependencies were found.

Not sure what is causing it yet though.