OYIon / LiveSharp

Public repository for the LiveSharp project
96 stars 4 forks source link

Bug: Not All Projects Are Detected #118

Closed warappa closed 1 year ago

warappa commented 3 years ago

LiveSharp 2.0.13 LiveSharp Server 2.0.6

Issue

I just discovered, that if LiveSharp is installed in more than one project, then not all projects are discovered.

In my case AssetManager.Web.Api.Contracts is detected, but AssetManager.Web.Api is not. Both have LiveSharp installed correctly.

As I debugged AssetManager.Web.Api and inspected ProjectInfo of ILiveSharpRuntime app in Configure(ILiveSharpRuntime app, I found that this project was wrongly detected as AssetManager.Web.Api.Contracts!

A screenshot: image

Possible Reason

My gut feeling suggests, that it may be an erroneous IndexOf(...) check that compares the project name/folderpath with already resolved projects. As AssetManager.Web.Api.Contracts is resolved earlier and AssetManager.Web.Api is a substring of AssetManager.Web.Api.Contracts I guess there is a false cache-hit or something.

warappa commented 3 years ago

Futher debugging: If I uninstall LiveSharp from AssetManager.Web.Api.Contracts - and recompile all - I get a different - but also wrong result for AssetManager.Web.Api: It detects AssetManager.Core!

image

ionoy commented 3 years ago

Thanks for the feedback!

LiveSharp populates the app object from the project it is initially running. What is the executing project in this solution?

warappa commented 3 years ago

That's a good point, because in this solution I have 2 startup-projects configured: AssetManager.Web.Api and AssetManager.UI.Blazor.Server. Nonetheless the app object represents none of them.

ionoy commented 3 years ago

Does AssetManager.Web.Api start from Program?

LiveSharp uses <Module> initializer to start itself in the recent versions. Is it possible that these other projects are somehow loaded before AssetManager.Web.Api?

warappa commented 3 years ago

Well, it could be that AssetManager.UI.Blazor.Server executes a bit faster (but it could just be random which one loads first).

warappa commented 3 years ago

The high level issue is, that LiveSharp.Server does not create a watch on all project directories (where LiveSharp is installed) and therefore misses the file-changes.

ionoy commented 3 years ago

LiveSharp uses ProjectReferences to determine what directories to watch. I feel like this is the issue with a wrong project connecting to the LiveSharp.Server before the correct one does. Is it a .net5 project? What if you use dotnet run to start it?

warappa commented 3 years ago

Is it then actually supported to have multiple startup-projects? Because naive me thought, that all projects (assemblies) that have LiveSharp installed, will connect to LiveSharp.Server and timing does not matter.

Yes, those are .NET 5 applications, but also uses .NET Standard 2.0 projects (i.e. AssetManager.Web.Api.Contracts for which a watcher got created).

When I'm back home I will try dotnet run.

warappa commented 3 years ago

@ dotnet run Note: This command doesn't support multiple startup projects. So I just ran AssetManager.Web.Api.

Running dotnet run -p .\AssetManager.Web.Api\ to only start AssetManager.Web.Api, also resulted in app.ProjectInfo.ProjectName to be AssetManager.Core instead of AssetManager.Web.Api.

Here's the output of LiveSharp.Server:

LiveSharp: Found available port: 50540
Welcome to LiveSharp!
You can open LiveSharp Dashboard in the browser at https://localhost.livesharp.net:50539
Hosting environment: Production
Content root path: C:\Users\WarappaLocal\.dotnet\tools\.store\livesharp.server\2.0.6\livesharp.server\2.0.6\tools\net5.0\any
Now listening on: http://[::]:50540
Now listening on: https://[::]:50539
Application started. Press Ctrl+C to shut down.
LiveSharp: Valid until Montag, 26. Juli 2021
LiveSharp: Starting dashboard process with arguments:  /SolutionPath="C:\Users\WarappaLocal\source\AssetManager\AssetManager.Core" /ProjectName="AssetManager.Core" /ProjectDir="C:\Users\WarappaLocal\source\AssetManager\AssetManager.Core" /NuGetPackagePath="C:\Users\WarappaLocal\.nuget\packages\livesharp\2.0.13\build" /ServerVersion="2.0.6" dashboard
23:01:05.205: Started listening on port 53518

23:01:05.209: Connecting to http://localhost:50540/connect/workspace

Hosting environment: Production
Content root path: C:\Users\WarappaLocal\.nuget\packages\livesharp\2.0.13\build\Workspace
Now listening on: https://[::]:53517
Application started. Press Ctrl+C to shut down.
23:01:05.259: client connected: 192.168.0.15:62758
23:01:05.429: Loading project AssetManager.Core
23:01:05.603: Loading project Core.Database.EntityFrameworkCore
23:01:05.604: LiveSharp not installed in Core.Database.EntityFrameworkCore
23:01:05.604: Loading project Core.DependencyInjection
23:01:05.604: LiveSharp not installed in Core.DependencyInjection
23:01:05.604: Loading project Core.Domain
23:01:05.604: LiveSharp not installed in Core.Domain
23:01:05.604: Loading project Core.IO.Contracts
23:01:05.605: LiveSharp not installed in Core.IO.Contracts
23:01:05.605: Loading project Core
23:01:05.605: LiveSharp not installed in Core
23:01:05.605: Loading project Core.Contracts
23:01:05.605: LiveSharp not installed in Core.Contracts
23:01:05.605: Loading project Core.Database.Contracts
23:01:05.605: LiveSharp not installed in Core.Database.Contracts
23:01:05.606: Loading project Core.Domain.Contracts
23:01:05.606: LiveSharp not installed in Core.Domain.Contracts
23:01:05.606: Loading project Core.Messaging
23:01:05.606: LiveSharp not installed in Core.Messaging
23:01:05.606: Loading project Core.Messaging.Contracts
23:01:05.606: LiveSharp not installed in Core.Messaging.Contracts
23:01:05.606: Loading project Core.Security
23:01:05.606: LiveSharp not installed in Core.Security
23:01:05.606: Loading project Core.Security.Contracts
23:01:05.607: LiveSharp not installed in Core.Security.Contracts
23:01:05.608: Workspace loading finished in 337ms
23:01:05.629: watcher created at C:\Users\WarappaLocal\source\AssetManager\AssetManager.Core\
23:01:05.635: Starting: Initial compilation AssetManager.Core
server:
Unable to retrieve the latest NuGet package version
System.ArgumentException: Version string portion was too short or too long. (Parameter 'input')
   at System.Version.ParseVersion(ReadOnlySpan`1 input, Boolean throwOnFailure)
   at System.Version.Parse(String input)
   at LiveSharp.Dashboard.WorkspaceInitializer.CheckForNuGetUpdates()
23:01:06.936: Finished: Initial compilation AssetManager.Core (1300)

It seems to be, that to launch AssetManager.Web.Api it has to load the referenced AssetManager.Core first, therefore AssetManager.Core gets initialized first. The module initialization seems to be "inside -> out", from inner to outer assemblies. This is verified by adding debug output to the Configure(ILiveSharpRuntime app) methods in both projects. It prints the following:

app.ProjectInfo.ProjectName in AssetManager.Core: AssetManager.Core
app.ProjectInfo.ProjectName in AssetManager.Web.Api: AssetManager.Core
ionoy commented 3 years ago

Interesting. How does it happen that referenced assembly is loaded before the main one?

I might need to rethink the project structure. Maybe just install LiveSharp in the main one and let users opt-in to referenced projects. This would make sure that there is only one entry point for LiveSharp.

ionoy commented 3 years ago

I started implementing this "single entry" feature and quickly realized that it's almost impossible to do with the current architecture. LiveSharp runtime depends on the information collected during the build time. So, unless there is a LiveSharp build task in each referenced project, I cannot load this project in the runtime.

So, change of plans. I have added a LiveSharpSkipStart attribute that you can put inside LiveSharp.dashboard.cs in those projects that shouldn't be used as entry points. I know, it's a less pretty solution because it doesn't solve the issue automatically, but it's easy to implement and it should be very reliable.

Anyway, please try the attached build and add [assembly: LiveSharpSkipStart] to AssetManager.Core\LiveSharp.dashboard.cs.

LiveSharp.2.0.16.zip

warappa commented 3 years ago

Thanks for the test package. I added the [assembly: LiveSharpSkipStart] attributes, and now the AssetManager.Web.Api is recognized as startup assembly.

Note: Projects are detected more than once and then multiple watchers are created for the same project (AssetManager.Core). I guess this shouldn't be this way.

Here's the LiveSharp.Server output:

LiveSharp: Found available port: 50540
Welcome to LiveSharp!
You can open LiveSharp Dashboard in the browser at https://localhost.livesharp.net:50539
Hosting environment: Production
Content root path: C:\Users\WarappaLocal\.dotnet\tools\.store\livesharp.server\2.0.6\livesharp.server\2.0.6\tools\net5.0\any
Now listening on: http://[::]:50540
Now listening on: https://[::]:50539
Application started. Press Ctrl+C to shut down.
LiveSharp: Valid until Montag, 26. Juli 2021
LiveSharp: Starting dashboard process with arguments:  /SolutionPath="C:\Users\WarappaLocal\source\AssetManager\AssetManager.sln" /ProjectName="AssetManager.Web.Api" /ProjectDir="C:\Users\WarappaLocal\source\AssetManager\AssetManager.Web.Api" /NuGetPackagePath="C:\Users\WarappaLocal\.nuget\packages\livesharp\2.0.16\build" /ServerVersion="2.0.6" dashboard
17:31:16.762: Started listening on port 54061

17:31:16.795: Connecting to http://localhost:50540/connect/workspace

Hosting environment: Production
Content root path: C:\Users\WarappaLocal\.nuget\packages\livesharp\2.0.16\build\Workspace
Now listening on: https://[::]:54060
Application started. Press Ctrl+C to shut down.
17:31:16.827: client connected: 192.168.0.15:59798
17:31:17.015: Loading project AssetManager.Web.Api
17:31:17.473: Loading project Core.Database.EntityFrameworkCore
17:31:17.473: LiveSharp not installed in Core.Database.EntityFrameworkCore
17:31:17.474: Loading project Core.DependencyInjection
17:31:17.474: LiveSharp not installed in Core.DependencyInjection
17:31:17.474: Loading project Core.IO
17:31:17.474: LiveSharp not installed in Core.IO
17:31:17.474: Loading project AssetManager.Core.AssetStorage.Filesystem
17:31:17.495: Loading project Core.DependencyInjection
17:31:17.495: LiveSharp not installed in Core.DependencyInjection
17:31:17.496: Loading project Core.IO.Contracts
17:31:17.496: LiveSharp not installed in Core.IO.Contracts
17:31:17.496: Loading project AssetManager.Core
17:31:17.514: Loading project Core.Database.EntityFrameworkCore
17:31:17.514: LiveSharp not installed in Core.Database.EntityFrameworkCore
17:31:17.514: Loading project Core.DependencyInjection
17:31:17.515: LiveSharp not installed in Core.DependencyInjection
17:31:17.515: Loading project Core.Domain
17:31:17.515: LiveSharp not installed in Core.Domain
17:31:17.515: Loading project Core.IO.Contracts
17:31:17.515: LiveSharp not installed in Core.IO.Contracts
17:31:17.516: Loading project Core
17:31:17.516: LiveSharp not installed in Core
17:31:17.516: Loading project Core.Contracts
17:31:17.516: LiveSharp not installed in Core.Contracts
17:31:17.516: Loading project Core.Database.Contracts
17:31:17.516: LiveSharp not installed in Core.Database.Contracts
17:31:17.517: Loading project Core.Domain.Contracts
17:31:17.517: LiveSharp not installed in Core.Domain.Contracts
17:31:17.517: Loading project Core.Messaging
17:31:17.518: LiveSharp not installed in Core.Messaging
17:31:17.518: Loading project Core.Messaging.Contracts
17:31:17.518: LiveSharp not installed in Core.Messaging.Contracts
17:31:17.519: Loading project Core.Security
17:31:17.519: LiveSharp not installed in Core.Security
17:31:17.519: Loading project Core.Security.Contracts
17:31:17.520: LiveSharp not installed in Core.Security.Contracts
17:31:17.520: Loading project Core
17:31:17.520: LiveSharp not installed in Core
17:31:17.520: Loading project Core.Contracts
17:31:17.521: LiveSharp not installed in Core.Contracts
17:31:17.522: Loading project Core.Database.Contracts
17:31:17.523: LiveSharp not installed in Core.Database.Contracts
17:31:17.523: Loading project Core.Database.EntityFrameworkCore
17:31:17.523: LiveSharp not installed in Core.Database.EntityFrameworkCore
17:31:17.523: Loading project Core.Domain
17:31:17.524: LiveSharp not installed in Core.Domain
17:31:17.524: Loading project Core.Domain.Contracts
17:31:17.524: LiveSharp not installed in Core.Domain.Contracts
17:31:17.525: Loading project Core.Messaging
17:31:17.525: LiveSharp not installed in Core.Messaging
17:31:17.525: Loading project Core.Messaging.Contracts
17:31:17.526: LiveSharp not installed in Core.Messaging.Contracts
17:31:17.526: Loading project Core.Security
17:31:17.526: LiveSharp not installed in Core.Security
17:31:17.527: Loading project Core.Security.Contracts
17:31:17.527: LiveSharp not installed in Core.Security.Contracts
17:31:17.527: Loading project AssetManager.Core.FileConversion.ImageSharp
17:31:17.544: Loading project AssetManager.Core
17:31:17.557: Loading project Core.Database.EntityFrameworkCore
17:31:17.557: LiveSharp not installed in Core.Database.EntityFrameworkCore
17:31:17.557: Loading project Core.DependencyInjection
17:31:17.558: LiveSharp not installed in Core.DependencyInjection
17:31:17.558: Loading project Core.Domain
17:31:17.558: LiveSharp not installed in Core.Domain
17:31:17.559: Loading project Core.IO.Contracts
17:31:17.559: LiveSharp not installed in Core.IO.Contracts
17:31:17.559: Loading project Core
17:31:17.560: LiveSharp not installed in Core
17:31:17.560: Loading project Core.Contracts
17:31:17.560: LiveSharp not installed in Core.Contracts
17:31:17.560: Loading project Core.Database.Contracts
17:31:17.561: LiveSharp not installed in Core.Database.Contracts
17:31:17.561: Loading project Core.Domain.Contracts
17:31:17.561: LiveSharp not installed in Core.Domain.Contracts
17:31:17.562: Loading project Core.Messaging
17:31:17.562: LiveSharp not installed in Core.Messaging
17:31:17.562: Loading project Core.Messaging.Contracts
17:31:17.562: LiveSharp not installed in Core.Messaging.Contracts
17:31:17.563: Loading project Core.Security
17:31:17.563: LiveSharp not installed in Core.Security
17:31:17.563: Loading project Core.Security.Contracts
17:31:17.564: LiveSharp not installed in Core.Security.Contracts
17:31:17.564: Loading project Core
17:31:17.564: LiveSharp not installed in Core
17:31:17.565: Loading project Core.Contracts
17:31:17.565: LiveSharp not installed in Core.Contracts
17:31:17.565: Loading project Core.Database.Contracts
17:31:17.565: LiveSharp not installed in Core.Database.Contracts
17:31:17.566: Loading project Core.Database.EntityFrameworkCore
17:31:17.566: LiveSharp not installed in Core.Database.EntityFrameworkCore
17:31:17.566: Loading project Core.DependencyInjection
17:31:17.567: LiveSharp not installed in Core.DependencyInjection
17:31:17.567: Loading project Core.Domain
17:31:17.567: LiveSharp not installed in Core.Domain
17:31:17.567: Loading project Core.Domain.Contracts
17:31:17.568: LiveSharp not installed in Core.Domain.Contracts
17:31:17.568: Loading project Core.IO.Contracts
17:31:17.568: LiveSharp not installed in Core.IO.Contracts
17:31:17.569: Loading project Core.Messaging
17:31:17.570: LiveSharp not installed in Core.Messaging
17:31:17.571: Loading project Core.Messaging.Contracts
17:31:17.571: LiveSharp not installed in Core.Messaging.Contracts
17:31:17.571: Loading project Core.Security
17:31:17.572: LiveSharp not installed in Core.Security
17:31:17.572: Loading project Core.Security.Contracts
17:31:17.573: LiveSharp not installed in Core.Security.Contracts
17:31:17.573: Loading project AssetManager.Core
17:31:17.586: Loading project Core.Database.EntityFrameworkCore
17:31:17.587: LiveSharp not installed in Core.Database.EntityFrameworkCore
17:31:17.587: Loading project Core.DependencyInjection
17:31:17.587: LiveSharp not installed in Core.DependencyInjection
17:31:17.588: Loading project Core.Domain
17:31:17.588: LiveSharp not installed in Core.Domain
17:31:17.588: Loading project Core.IO.Contracts
17:31:17.588: LiveSharp not installed in Core.IO.Contracts
17:31:17.589: Loading project Core
17:31:17.589: LiveSharp not installed in Core
17:31:17.589: Loading project Core.Contracts
17:31:17.590: LiveSharp not installed in Core.Contracts
17:31:17.590: Loading project Core.Database.Contracts
17:31:17.590: LiveSharp not installed in Core.Database.Contracts
17:31:17.591: Loading project Core.Domain.Contracts
17:31:17.591: LiveSharp not installed in Core.Domain.Contracts
17:31:17.591: Loading project Core.Messaging
17:31:17.592: LiveSharp not installed in Core.Messaging
17:31:17.592: Loading project Core.Messaging.Contracts
17:31:17.592: LiveSharp not installed in Core.Messaging.Contracts
17:31:17.592: Loading project Core.Security
17:31:17.593: LiveSharp not installed in Core.Security
17:31:17.593: Loading project Core.Security.Contracts
17:31:17.593: LiveSharp not installed in Core.Security.Contracts
17:31:17.594: Loading project AssetManager.Web.Api.Contracts
17:31:17.609: Loading project Core.Database.Contracts
17:31:17.610: LiveSharp not installed in Core.Database.Contracts
17:31:17.610: Loading project Core
17:31:17.611: LiveSharp not installed in Core
17:31:17.611: Loading project Core.Contracts
17:31:17.611: LiveSharp not installed in Core.Contracts
17:31:17.611: Loading project Core.Database.Contracts
17:31:17.612: LiveSharp not installed in Core.Database.Contracts
17:31:17.612: Loading project Core.Domain
17:31:17.612: LiveSharp not installed in Core.Domain
17:31:17.613: Loading project Core.Domain.Contracts
17:31:17.613: LiveSharp not installed in Core.Domain.Contracts
17:31:17.613: Loading project Core.IO.Contracts
17:31:17.613: LiveSharp not installed in Core.IO.Contracts
17:31:17.614: Loading project Core.Messaging
17:31:17.614: LiveSharp not installed in Core.Messaging
17:31:17.614: Loading project Core.Messaging.Contracts
17:31:17.615: LiveSharp not installed in Core.Messaging.Contracts
17:31:17.615: Loading project Core.Security
17:31:17.615: LiveSharp not installed in Core.Security
17:31:17.615: Loading project Core.Security.Contracts
17:31:17.616: LiveSharp not installed in Core.Security.Contracts
17:31:17.618: Workspace loading finished in 778ms
17:31:17.639: watcher created at C:\Users\WarappaLocal\source\AssetManager\AssetManager.Web.Api\
17:31:17.644: watcher created at C:\Users\WarappaLocal\source\AssetManager\AssetManager.Core.AssetStorage.Filesystem\
17:31:17.644: watcher created at C:\Users\WarappaLocal\source\AssetManager\AssetManager.Core\
17:31:17.645: watcher created at C:\Users\WarappaLocal\source\AssetManager\AssetManager.Core.FileConversion.ImageSharp\
17:31:17.645: watcher created at C:\Users\WarappaLocal\source\AssetManager\AssetManager.Core\
17:31:17.645: watcher created at C:\Users\WarappaLocal\source\AssetManager\AssetManager.Core\
17:31:17.646: watcher created at C:\Users\WarappaLocal\source\AssetManager\AssetManager.Web.Api.Contracts\
17:31:17.647: Starting: Initial compilation AssetManager.Web.Api
server: 2.0.6
nuget: 2.0.16
17:31:21.380: Finished: Initial compilation AssetManager.Web.Api (3732)

PS: I almost wrote that it doesn't work. But fortunately I remembered that MSBuild-tasks cannot be unloaded. Maybe a warning/error should be shown if I update LiveSharp but don't close and re-open Visual Studio.