microsoft / SimpleStubs

*SimpleStubs* is a simple mocking framework that supports Universal Windows Platform (UWP), .NET Core and .NET framework. SimpleStubs is currently developed and maintained by Microsoft BigPark Studios in Vancouver.
Other
66 stars 29 forks source link

Upgrade to VS2019 - Stubs not generated #55

Closed ScottyLightnin closed 5 years ago

ScottyLightnin commented 5 years ago

Anyone tried upgrading to VS2019? My solution generates stubs just fine in 2017, but fails in VS2019. Any clues?

nehme-bilal-ah commented 5 years ago

@ScottyLightnin Thanks for reporting. @velocitysystems seem the same issue and reported it in #53. I will install VS 2019 soon and try to find out what is going on.

nehme-bilal-ah commented 5 years ago

@ScottyLightnin Can you expand more on how it is failing? Are you getting an error or is it just missing the stubs?

ScottyLightnin commented 5 years ago

@nehme-bilal-ah it doesn't generate the stubs file in VS2019. If I open the same solution in VS2017 and rebuild, the SimpleStubs.generated.cs file appears. Reopen back in VS2019 and rebuild, SimpleStubs.generated.cs becomes empty.

nehme-bilal-ah commented 5 years ago

Hmm ok weird.. Are you seeing issues in the build output? I tested on a .net standard class library in VS2019 and everything works as expected for me (except some intellisense issues in VS).

Please provide more info on your setup, I can't help if I can't repro.

ScottyLightnin commented 5 years ago

I appreciate your attention @nehme-bilal-ah thank you. If it makes a difference, it's a UWP app. Our solution has a "GeneratedStubs" UWP project, that references all the shared UWP projects in the solution. Our UnitTest projects then reference this GeneratedStubs project.

As for the output:

10> SimpleStubs: Generating stubs for project: C:\Git....\Universal.UnitTests.GeneratedStubs.csproj 10> Simplestubs encountered errors when opening the workspace; Stubs will be generated only for projects that successfully opened. Errors: [Failure] Msbuild failed when processing the file 'C:\Git....\Universal.UnitTests.GeneratedStubs\Universal.UnitTests.GeneratedStubs.csproj' with message: The imported project "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\WindowsXaml\v16.0\Microsoft.Windows.UI.Xaml.CSharp.targets" was not found. Also, tried to find "Microsoft\WindowsXaml\v16.0\Microsoft.Windows.UI.Xaml.CSharp.targets" in the fallback search path(s) for $(MSBuildExtensionsPath) - "C:\Program Files (x86)\MSBuild" . These search paths are defined in "C:\Users\sferguson.nuget\packages\etg.simplestubs\2.4.7\tools\Etg.SimpleStubs.CodeGen.exe.Config". Confirm that the path in the declaration is correct, and that the file exists on disk in one of the search paths. C:\Git....\Universal.UnitTests.GeneratedStubs\Universal.UnitTests.GeneratedStubs.csproj 10>
10> SimpleStubs: Writing stubs to file: obj\x86\Debug\SimpleStubs.generated.cs

N.B. I find this interesting that it's trying to find a VS2017 project...

nehme-bilal-ah commented 5 years ago

@ScottyLightnin thanks for the details. I am currently travelling for few days and don't have UWP installed on my laptop. I will install it when I get back home. In the meantime, can you try it with a fresh class library? Maybe for both .Net Standard and UWP?

I will look into what is going on with the MSBuild path but I this could be related to #39 and the fix might be as simple as upgrading the package Microsoft.Build.Locator (I just saw that the latest version was uploaded a day ago, which might be adding support to VS2019).

nehme-bilal-ah commented 5 years ago

Ok I was able to repro on a UWP class library. I tried updating MSBuildLocator and the Roslyn NuGet packages and now I am getting the error below. Maybe @DustinCampbell from Roslyn team knows why?

1>------ Build started: Project: Stubs, Configuration: Debug Any CPU ------
1>  SimpleStubs: Generating stubs for project: C:\Users\Nehme\source\repos\UWPLib\Stubs\Stubs.csproj
1>  SimpleStubs: Failed to generate stubs: System.AggregateException: One or more errors occurred. ---> System.TypeInitializationException: The type initializer for 'Microsoft.Build.Shared.NativeMethodsShared' threw an exception. ---> System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime.InteropServices.RuntimeInformation, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
1>     at Microsoft.Build.Shared.NativeMethodsShared.get_IsLinux()
1>     at Microsoft.Build.Shared.NativeMethodsShared..cctor()
1>     --- End of inner exception stack trace ---
1>     at Microsoft.Build.Shared.NativeMethodsShared.get_IsMono()
1>     at Microsoft.Build.BackEnd.Logging.LoggingService..ctor(LoggerMode loggerMode, Int32 nodeId)
1>     at Microsoft.Build.Evaluation.ProjectCollection.CreateLoggingService(Int32 maxCPUCount, Boolean onlyLogCriticalEvents)
1>     at Microsoft.Build.Evaluation.ProjectCollection..ctor(IDictionary`2 globalProperties, IEnumerable`1 loggers, IEnumerable`1 remoteLoggers, ToolsetDefinitionLocations toolsetDefinitionLocations, Int32 maxNodeCount, Boolean onlyLogCriticalEvents)
1>     at Microsoft.Build.Evaluation.ProjectCollection..ctor(IDictionary`2 globalProperties)
1>     at Microsoft.CodeAnalysis.MSBuild.Build.ProjectBuildManager.StartBatchBuild(IDictionary`2 globalProperties)
1>     at Microsoft.CodeAnalysis.MSBuild.MSBuildProjectLoader.Worker.<LoadAsync>d__18.MoveNext()
1>  --- End of stack trace from previous location where exception was thrown ---
1>     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
1>     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
1>     at Microsoft.CodeAnalysis.MSBuild.MSBuildProjectLoader.<LoadProjectInfoAsync>d__22.MoveNext()
1>  --- End of stack trace from previous location where exception was thrown ---
1>     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
1>     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
1>     at Microsoft.CodeAnalysis.MSBuild.MSBuildWorkspace.<OpenProjectAsync>d__24.MoveNext()
1>  --- End of stack trace from previous location where exception was thrown ---
1>     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
1>     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
1>     at Etg.SimpleStubs.CodeGen.SimpleStubsGenerator.<GenerateStubs>d__3.MoveNext()
1>     --- End of inner exception stack trace ---
1>     at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
1>     at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
1>     at System.Threading.Tasks.Task`1.get_Result()
1>     at Etg.SimpleStubs.CodeGen.Program.Main(String[] args)
1>  ---> (Inner Exception #0) System.TypeInitializationException: The type initializer for 'Microsoft.Build.Shared.NativeMethodsShared' threw an exception. ---> System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime.InteropServices.RuntimeInformation, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
1>     at Microsoft.Build.Shared.NativeMethodsShared.get_IsLinux()
1>     at Microsoft.Build.Shared.NativeMethodsShared..cctor()
1>     --- End of inner exception stack trace ---
1>     at Microsoft.Build.Shared.NativeMethodsShared.get_IsMono()
1>     at Microsoft.Build.BackEnd.Logging.LoggingService..ctor(LoggerMode loggerMode, Int32 nodeId)
1>     at Microsoft.Build.Evaluation.ProjectCollection.CreateLoggingService(Int32 maxCPUCount, Boolean onlyLogCriticalEvents)
1>     at Microsoft.Build.Evaluation.ProjectCollection..ctor(IDictionary`2 globalProperties, IEnumerable`1 loggers, IEnumerable`1 remoteLoggers, ToolsetDefinitionLocations toolsetDefinitionLocations, Int32 maxNodeCount, Boolean onlyLogCriticalEvents)
1>     at Microsoft.Build.Evaluation.ProjectCollection..ctor(IDictionary`2 globalProperties)
1>     at Microsoft.CodeAnalysis.MSBuild.Build.ProjectBuildManager.StartBatchBuild(IDictionary`2 globalProperties)
1>     at Microsoft.CodeAnalysis.MSBuild.MSBuildProjectLoader.Worker.<LoadAsync>d__18.MoveNext()
1>  --- End of stack trace from previous location where exception was thrown ---
1>     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
1>     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
1>     at Microsoft.CodeAnalysis.MSBuild.MSBuildProjectLoader.<LoadProjectInfoAsync>d__22.MoveNext()
1>  --- End of stack trace from previous location where exception was thrown ---
1>     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
1>     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
1>     at Microsoft.CodeAnalysis.MSBuild.MSBuildWorkspace.<OpenProjectAsync>d__24.MoveNext()
1>  --- End of stack trace from previous location where exception was thrown ---
1>     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
1>     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
1>     at Etg.SimpleStubs.CodeGen.SimpleStubsGenerator.<GenerateStubs>d__3.MoveNext()<---
nehme-bilal-ah commented 5 years ago

I believe the issue is fixed now.

@ScottyLightnin @velocitysystems please try the package SimpleStubs 2.4.8.

Note that this is not the same Etg.SimpleStubs package because I don't work for Microsoft anymore and lost access to the original NuGet feed.

velocitysystems commented 5 years ago

Thanks @nehme-bilal-ah, I just tried updating our .NETStandard stubs project to 2.4.8. It builds fine now with no warnings or errors, but no stubs file is generated?

nehme-bilal-ah commented 5 years ago

Oops sorry, I needed to rename the target file to match the new NuGet package name. However, somehow we're back to the original error:

SimpleStubs: Generating stubs for project: C:\Users\Nehme\source\repos\UWPLib\Stubs\Stubs.csproj
2>  Simplestubs encountered errors when opening the workspace; Stubs will be generated only for projects that successfully opened. Errors: [Failure] Msbuild failed when processing the file 'C:\Users\Nehme\source\repos\UWPLib\Stubs\Stubs.csproj' with message: The imported project "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\WindowsXaml\v16.0\Microsoft.Windows.UI.Xaml.CSharp.targets" was not found. Also, tried to find "Microsoft\WindowsXaml\v16.0\Microsoft.Windows.UI.Xaml.CSharp.targets" in the fallback search path(s) for $(MSBuildExtensionsPath) - "C:\Program Files (x86)\MSBuild" . These search paths are defined in "C:\Users\Nehme\.nuget\packages\simplestubs\2.4.8.1\tools\Etg.SimpleStubs.CodeGen.exe.Config". Confirm that the path in the <Import> declaration is correct, and that the file exists on disk in one of the search paths.  C:\Users\Nehme\source\repos\UWPLib\Stubs\Stubs.csproj
2>  
2>  SimpleStubs: Writing stubs to file: obj\Debug\SimpleStubs.generated.cs

I have to investigate more.

nehme-bilal-ah commented 5 years ago

The issue is likely related to MSBuildLocator not supporting VS2019 yet. I opened an issue here.

ScottyLightnin commented 5 years ago

thanks @nehme-bilal-ah

nehme-bilal-ah commented 5 years ago

Ok @ScottyLightnin @velocitysystems please try 2.4.8.2.

ScottyLightnin commented 5 years ago

Issue resolved thank you @nehme-bilal-ah :) Great work.

velocitysystems commented 5 years ago

@nehme-bilal-ah Yes, works perfectly now under VS2019. Thanks ever so much! :)

nehme-bilal-ah commented 5 years ago

Great! thanks for your help guys :)