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

Latest version does not compile when test project has x64-only project reference #37

Closed billyzkid closed 6 years ago

billyzkid commented 6 years ago

Even though I have specified the x64 build configuration for my solution and in my Tests project settings, SimpleStubs appears to force one of my project references to compile using "Any CPU" which will not work as this project includes native dependencies (ADBMobile) and can only target x86, x64, or ARM. If I unload the Tests project, the solution builds fine.

This did not occur in the previous version of SimpleStubs.

Here is the relevant error output:

10>  SimpleStubs: Generating stubs for project: C:\Code\Foo\Tests\Tests.csproj
10>  SimpleStubs: Failed to generate stubs: System.AggregateException: One or more errors occurred. ---> System.Exception: Failed to open project, Errors: [Failure] Msbuild failed when processing the file 'C:\Code\Foo\SDK\SDK.csproj' with message: C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets: (2307, 5): The processor architecture of the project being built "Any CPU" is not supported by the referenced SDK "ADBMobile, Version=4.0". Please consider changing the targeted processor architecture of your project (in Visual Studio this can be done through the Configuration Manager) to one of the architectures supported by the SDK: "x86, ARM, x64".
10>  C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets: (2307, 5): The processor architecture of the project being built "Any CPU" is not supported by the referenced SDK "Microsoft.VCLibs, Version=14.0". Please consider changing the targeted processor architecture of your project (in Visual Studio this can be done through the Configuration Manager) to one of the architectures supported by the SDK: "x86, x64, ARM, ARM64".
10>  C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets: (2307, 5): The processor architecture of the project being built "Any CPU" is not supported by the referenced SDK "Microsoft.VCLibs.120, Version=14.0". Please consider changing the targeted processor architecture of your project (in Visual Studio this can be done through the Configuration Manager) to one of the architectures supported by the SDK: "x86, x64, ARM".
10>  
10>     at Etg.SimpleStubs.CodeGen.SimpleStubsGenerator.<GenerateStubs>d__3.MoveNext()
10>     --- End of inner exception stack trace ---
10>     at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
10>     at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
10>     at System.Threading.Tasks.Task`1.get_Result()
10>     at Etg.SimpleStubs.CodeGen.Program.Main(String[] args)
10>  ---> (Inner Exception #0) System.Exception: Failed to open project, Errors: [Failure] Msbuild failed when processing the file 'C:\Code\Foo\SDK\SDK.csproj' with message: C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets: (2307, 5): The processor architecture of the project being built "Any CPU" is not supported by the referenced SDK "ADBMobile, Version=4.0". Please consider changing the targeted processor architecture of your project (in Visual Studio this can be done through the Configuration Manager) to one of the architectures supported by the SDK: "x86, ARM, x64".
10>  C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets: (2307, 5): The processor architecture of the project being built "Any CPU" is not supported by the referenced SDK "Microsoft.VCLibs, Version=14.0". Please consider changing the targeted processor architecture of your project (in Visual Studio this can be done through the Configuration Manager) to one of the architectures supported by the SDK: "x86, x64, ARM, ARM64".
10>  C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets: (2307, 5): The processor architecture of the project being built "Any CPU" is not supported by the referenced SDK "Microsoft.VCLibs.120, Version=14.0". Please consider changing the targeted processor architecture of your project (in Visual Studio this can be done through the Configuration Manager) to one of the architectures supported by the SDK: "x86, x64, ARM".
10>  
10>     at Etg.SimpleStubs.CodeGen.SimpleStubsGenerator.<GenerateStubs>d__3.MoveNext()<---
10>  
10>CSC : error CS2001: Source file 'C:\Code\Foo\Tests\obj\x64\Debug\SimpleStubs.generated.cs' could not be found.
========== Rebuild All: 9 succeeded, 1 failed, 0 skipped ==========
nehmebilal commented 6 years ago

@billyzkid. Thanks for reporting. I will change the behavior to ignore projects that fail to load (some console output will still show up to warn you that subs were not generated for these projects).

nehmebilal commented 6 years ago

Hmm second thought.. I should be able to pass the build architecture down to simplestubs to make sure that roslyn load all projects using the specified architecture.

billyzkid commented 6 years ago

But what if I need stubs for these projects? Why is SimpleStubs trying to build this project in "Any CPU" when my build config/architecture is set to x64 for all projects?

Edit: just saw your 2nd comment. So we should be good to go once that's fixed then?

nehmebilal commented 6 years ago

We need to pass down the $(Platform) to MSBuildWorkspace the same way we did for $(Configuration) here.

nehmebilal commented 6 years ago

@billyzkid You're welcome to send a PR for this if it's clear to you what needs to be done. Otherwise, I'll try to do it as soon as I find some time.

billyzkid commented 6 years ago

Thanks. It seems pretty straightforward, but unfortunately I can't afford the time to setup the necessary dev environment and properly test at the moment. For now, I'm reverting to the previous version, but am happy to test/confirm the next one as soon as the fix is released for this.

nehmebilal commented 6 years ago

@billyzkid 2.4.3 published, please give it a try!

billyzkid commented 6 years ago

@nehmebilal It works! Thanks!

nehmebilal commented 6 years ago

Glad to hear!