dotnet / sdk

Core functionality needed to create .NET Core projects, that is shared between Visual Studio and CLI
https://dot.net/core
MIT License
2.7k stars 1.06k forks source link

VSSettings fails with DotNetCliToolReference in VS for Mac #10570

Open daniel-white opened 5 years ago

daniel-white commented 5 years ago

Steps to reproduce

* Build with VS for Mac
* Build from terminal (`dotnet build`)

## Expected  behavior
The swagger tool is run as it does from the CLI.

## Actual behavior
Fails to find tool in mac

dotnet -d swagger Telemetry is: Enabled projectfactory: MSBUILD_EXE_PATH = /Users/daniel.white/Library/Caches/VisualStudio/8.0/MSBuild/887671/MonoDevelop.MSBuildBuilder.exe projectfactory: MSBuild project path = /Users/daniel.white/Builds/foo/foo.csproj Microsoft.Build.Exceptions.InvalidProjectFileException: The SDK resolver type "DotNetMSBuildSdkResolver" failed to load. The type initializer for 'Microsoft.DotNet.MSBuildSdkResolver.VSSettings' threw an exception. /Users/daniel.white/Builds/foo/foo.csproj ---> System.TypeInitializationException: The type initializer for 'Microsoft.DotNet.MSBuildSdkResolver.VSSettings' threw an exception. ---> System.TypeInitializationException: The type initializer for 'Microsoft.DotNet.MSBuildSdkResolver.Interop' threw an exception. ---> System.TypeLoadException: Could not load type 'System.Runtime.InteropServices.OSPlatform' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. --- End of inner exception stack trace --- at Microsoft.DotNet.MSBuildSdkResolver.VSSettings..ctor() in //src/Microsoft.DotNet.MSBuildSdkResolver/VSSettings.cs:line 30 at Microsoft.DotNet.MSBuildSdkResolver.VSSettings..cctor() in //src/Microsoft.DotNet.MSBuildSdkResolver/VSSettings.cs:line 25 Microsoft.DotNet.Cli.Utils.CommandUnknownException: No executable found matching command "dotnet-swagger" at Microsoft.DotNet.Cli.Utils.Command.Create(ICommandResolverPolicy commandResolverPolicy, String commandName, IEnumerable1 args, NuGetFramework framework, String configuration, String outputPath, String applicationName) at Microsoft.DotNet.Cli.Utils.Command.Create(String commandName, IEnumerable1 args, NuGetFramework framework, String configuration, String outputPath, String applicationName) at Microsoft.DotNet.Cli.Program.ProcessArgs(String[] args, ITelemetry telemetryClient) at Microsoft.DotNet.Cli.Program.Main(String[] args) --- End of inner exception stack trace --- at Microsoft.DotNet.MSBuildSdkResolver.DotNetMSBuildSdkResolver..ctor() in //src/Microsoft.DotNet.MSBuildSdkResolver/MSBuildSdkResolver.cs:line 38 --- End of inner exception stack trace --- at Microsoft.Build.Shared.ProjectFileErrorUtilities.VerifyThrowInvalidProjectFile(Boolean condition, String errorSubCategoryResourceName, BuildEventFileInfo projectFile, Exception innerException, String resourceName, Object[] args) at Microsoft.Build.Shared.ProjectFileErrorUtilities.ThrowInvalidProjectFile(BuildEventFileInfo projectFile, Exception innerException, String resourceName, Object[] args) at Microsoft.Build.BackEnd.SdkResolution.SdkResolverLoader.LoadResolvers(String resolverPath, LoggingContext loggingContext, ElementLocation location, List1 resolvers) at Microsoft.Build.BackEnd.SdkResolution.SdkResolverLoader.LoadResolvers(LoggingContext loggingContext, ElementLocation location) at Microsoft.Build.BackEnd.SdkResolution.SdkResolverService.Initialize(LoggingContext loggingContext, ElementLocation location) at Microsoft.Build.BackEnd.SdkResolution.SdkResolverService.ResolveSdk(Int32 submissionId, SdkReference sdk, LoggingContext loggingContext, ElementLocation sdkReferenceLocation, String solutionPath, String projectPath, Boolean interactive) at Microsoft.Build.BackEnd.SdkResolution.CachingSdkResolverService.<>c__DisplayClass3_0.<ResolveSdk>b__0(String key) at System.Collections.Concurrent.ConcurrentDictionary2.GetOrAdd(TKey key, Func2 valueFactory) at Microsoft.Build.BackEnd.SdkResolution.CachingSdkResolverService.ResolveSdk(Int32 submissionId, SdkReference sdk, LoggingContext loggingContext, ElementLocation sdkReferenceLocation, String solutionPath, String projectPath, Boolean interactive) at Microsoft.Build.Evaluation.Evaluator4.ExpandAndLoadImportsFromUnescapedImportExpressionConditioned(String directoryOfImportingFile, ProjectImportElement importElement, List1& projects, SdkResult& sdkResult, Boolean throwOnFileNotExistsError) at Microsoft.Build.Evaluation.Evaluator4.ExpandAndLoadImports(String directoryOfImportingFile, ProjectImportElement importElement, SdkResult& sdkResult) at Microsoft.Build.Evaluation.Evaluator4.EvaluateImportElement(String directoryOfImportingFile, ProjectImportElement importElement) at Microsoft.Build.Evaluation.Evaluator4.PerformDepthFirstPass(ProjectRootElement currentProjectOrImport) at Microsoft.Build.Evaluation.Evaluator4.Evaluate(ILoggingService loggingService, BuildEventContext buildEventContext) at Microsoft.Build.Evaluation.Project.Reevaluate(ILoggingService loggingServiceForEvaluation, ProjectLoadSettings loadSettings, EvaluationContext evaluationContext) at Microsoft.Build.Evaluation.Project.ReevaluateIfNecessary(ILoggingService loggingServiceForEvaluation, ProjectLoadSettings loadSettings, EvaluationContext evaluationContext) at Microsoft.Build.Evaluation.Project.Initialize(IDictionary2 globalProperties, String toolsVersion, String subToolsetVersion, ProjectLoadSettings loadSettings, EvaluationContext evaluationContext) at Microsoft.Build.Evaluation.Project..ctor(String projectFile, IDictionary2 globalProperties, String toolsVersion, String subToolsetVersion, ProjectCollection projectCollection, ProjectLoadSettings loadSettings, EvaluationContext evaluationContext) at Microsoft.Build.Evaluation.ProjectCollection.LoadProject(String fileName, IDictionary2 globalProperties, String toolsVersion) at Microsoft.DotNet.Cli.Utils.MSBuildProject..ctor(String msBuildProjectPath, NuGetFramework framework, String configuration, String outputPath, String msBuildExePath) at Microsoft.DotNet.Cli.Utils.ProjectFactory.GetMSBuildProj(String projectDirectory, NuGetFramework framework, String configuration, String outputPath) projecttoolscommandresolver: ProjectFactory did not find Project. /Users/daniel.white/Builds/foo/foo.csproj(12,5): error MSB3073: The command "dotnet -d swagger" exited with code 1. Done building project "foo.csproj" -- FAILED.


## Environment data
`dotnet --info` output:
(from inside VS for Mac)

.NET Core SDK (reflecting any global.json): Version: 2.1.802 Commit: 177d0b2525

Runtime Environment: OS Name: Mac OS X OS Version: 10.14 OS Platform: Darwin RID: osx.10.14-x64 Base Path: /usr/local/share/dotnet/sdk/2.1.802/

Host (useful for support): Version: 3.0.0 Commit: 7d57652f33

.NET Core SDKs installed: 2.1.504 [/usr/local/share/dotnet/sdk] 2.1.802 [/usr/local/share/dotnet/sdk] 3.0.100 [/usr/local/share/dotnet/sdk]

.NET Core runtimes installed: Microsoft.AspNetCore.All 2.1.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.7 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.8 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.9 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.11 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.12 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.13 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.7 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.8 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.9 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.11 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.12 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.13 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.0.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.1.2 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.7 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.8 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.9 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.11 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.12 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.13 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 3.0.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

livarcocc commented 5 years ago

@nguerrera can you take a look?

nguerrera commented 5 years ago

Could not load type 'System.Runtime.InteropServices.OSPlatform' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'

This seems like an issue with the version of mono getting used. cc @radical

daniel-white commented 5 years ago

Yea I suspected that after seeing that error message. It appears that Exec is looking for dotnet ... and replacing that with a loader inside of the Mono CLR to call the tool. I had a thought this morning and I'll give it a go.

bgever commented 4 years ago

Having the same issue with own tool, VS for Mac 8.5, SDK 3.1.200. Error:

Microsoft.Build.Exceptions.InvalidProjectFileException: The imported project "/Users/bart/Library/Caches/VisualStudio/8.0/MSBuild/44824_1/Current/Microsoft.Common.props" was not found. Confirm that the expression in the Import declaration "/Users/bart/Library/Caches/VisualStudio/8.0/MSBuild/44824_1/Current/Microsoft.Common.props" is correct, and that the file exists on disk.  /usr/local/share/dotnet/sdk/3.1.200/Sdks/Microsoft.NET.Sdk/Sdk/Sdk.props

I've checked and the the /Current folder doesn't exist on disk.

<Project ToolsVersion="15.0" Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFramework>netcoreapp2.2</TargetFramework>
    <!-- ... -->
  </PropertyGroup>
  <Target Name="PreBuild" BeforeTargets="PreBuildEvent" Condition=" '$(WithoutHooks)' != 'true' ">
    <Exec Command="dotnet -d publish-plugins $(OutDir)" WorkingDirectory="$(ProjectDir)" />
  </Target>
  <!-- ... -->
  <ItemGroup>
    <DotNetCliToolReference Include="Company.Tools.PublishPlugins" Version="1.0.9" />
  </ItemGroup>
  <!-- ... -->
</Project>
    dotnet -d publish-plugins bin/Debug/netcoreapp2.2/
    Telemetry is: Enabled
    projectfactory: MSBUILD_EXE_PATH = /Users/bart/Library/Caches/VisualStudio/8.0/MSBuild/44824_1/MonoDevelop.MSBuildBuilder.exe
    projectfactory: MSBuild project path = /Users/bart/repos/qf/Source/Apps/WebApp/Company.WebApp/Company.WebApp.csproj
    Microsoft.Build.Exceptions.InvalidProjectFileException: The imported project "/Users/bart/Library/Caches/VisualStudio/8.0/MSBuild/44824_1/Current/Microsoft.Common.props" was not found. Confirm that the expression in the Import declaration "/Users/bart/Library/Caches/VisualStudio/8.0/MSBuild/44824_1/Current/Microsoft.Common.props" is correct, and that the file exists on disk.  /usr/local/share/dotnet/sdk/3.1.200/Sdks/Microsoft.NET.Sdk/Sdk/Sdk.props
    Microsoft.DotNet.Cli.Utils.CommandUnknownException: Could not execute because the specified command or file was not found.
    Possible reasons for this include:
      * You misspelled a built-in dotnet command.
      * You intended to execute a .NET Core program, but dotnet-publish-plugins does not exist.
      * You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.
       at Microsoft.DotNet.CommandFactory.CommandFactoryUsingResolver.Create(ICommandResolverPolicy commandResolverPolicy, String commandName, IEnumerable`1 args, NuGetFramework framework, String configuration, String outputPath, String applicationName)
       at Microsoft.DotNet.Cli.Program.ProcessArgs(String[] args, ITelemetry telemetryClient)
       at Microsoft.DotNet.Cli.Program.Main(String[] args)
       at Microsoft.Build.Shared.ProjectErrorUtilities.ThrowInvalidProject(String errorSubCategoryResourceName, IElementLocation elementLocation, String resourceName, Object[] args)
       at Microsoft.Build.Shared.ProjectErrorUtilities.ThrowInvalidProject[T1,T2](IElementLocation elementLocation, String resourceName, T1 arg0, T2 arg1)
       at Microsoft.Build.Evaluation.Evaluator`4.ExpandAndLoadImportsFromUnescapedImportExpression(String directoryOfImportingFile, ProjectImportElement importElement, String unescapedExpression, Boolean throwOnFileNotExistsError, List`1& imports)
       at Microsoft.Build.Evaluation.Evaluator`4.ExpandAndLoadImportsFromUnescapedImportExpressionConditioned(String directoryOfImportingFile, ProjectImportElement importElement, List`1& projects, SdkResult& sdkResult, Boolean throwOnFileNotExistsError)
       at Microsoft.Build.Evaluation.Evaluator`4.ExpandAndLoadImports(String directoryOfImportingFile, ProjectImportElement importElement, SdkResult& sdkResult)
       at Microsoft.Build.Evaluation.Evaluator`4.EvaluateImportElement(String directoryOfImportingFile, ProjectImportElement importElement)
       at Microsoft.Build.Evaluation.Evaluator`4.PerformDepthFirstPass(ProjectRootElement currentProjectOrImport)
       at Microsoft.Build.Evaluation.Evaluator`4.EvaluateImportElement(String directoryOfImportingFile, ProjectImportElement importElement)
       at Microsoft.Build.Evaluation.Evaluator`4.PerformDepthFirstPass(ProjectRootElement currentProjectOrImport)
       at Microsoft.Build.Evaluation.Evaluator`4.EvaluateImportElement(String directoryOfImportingFile, ProjectImportElement importElement)
       at Microsoft.Build.Evaluation.Evaluator`4.PerformDepthFirstPass(ProjectRootElement currentProjectOrImport)
       at Microsoft.Build.Evaluation.Evaluator`4.Evaluate(ILoggingService loggingService, BuildEventContext buildEventContext)
       at Microsoft.Build.Evaluation.Evaluator`4.Evaluate(IEvaluatorData`4 data, ProjectRootElement root, ProjectLoadSettings loadSettings, Int32 maxNodeCount, PropertyDictionary`1 environmentProperties, ILoggingService loggingService, IItemFactory`2 itemFactory, IToolsetProvider toolsetProvider, ProjectRootElementCacheBase projectRootElementCache, BuildEventContext buildEventContext, ISdkResolverService sdkResolverService, Int32 submissionId, EvaluationContext evaluationContext, Boolean interactive)
       at Microsoft.Build.Evaluation.Project.ProjectImpl.Reevaluate(ILoggingService loggingServiceForEvaluation, ProjectLoadSettings loadSettings, EvaluationContext evaluationContext)
       at Microsoft.Build.Evaluation.Project.ProjectImpl.ReevaluateIfNecessary(ILoggingService loggingServiceForEvaluation, ProjectLoadSettings loadSettings, EvaluationContext evaluationContext)
       at Microsoft.Build.Evaluation.Project.ProjectImpl.ReevaluateIfNecessary(EvaluationContext evaluationContext)
       at Microsoft.Build.Evaluation.Project.ProjectImpl.Initialize(IDictionary`2 globalProperties, String toolsVersion, String subToolsetVersion, ProjectLoadSettings loadSettings, EvaluationContext evaluationContext)
       at Microsoft.Build.Evaluation.Project..ctor(String projectFile, IDictionary`2 globalProperties, String toolsVersion, String subToolsetVersion, ProjectCollection projectCollection, ProjectLoadSettings loadSettings, EvaluationContext evaluationContext)
       at Microsoft.Build.Evaluation.ProjectCollection.LoadProject(String fileName, IDictionary`2 globalProperties, String toolsVersion)
       at Microsoft.DotNet.CommandFactory.MSBuildProject..ctor(String msBuildProjectPath, NuGetFramework framework, String configuration, String outputPath, String msBuildExePath)
       at Microsoft.DotNet.CommandFactory.ProjectFactory.GetMSBuildProj(String projectDirectory, NuGetFramework framework, String configuration, String outputPath)
    projecttoolscommandresolver: ProjectFactory did not find Project.
    /Users/bart/repos/qf/Source/Apps/WebApp/Company.WebApp/Company.WebApp.csproj(15,5): error MSB3073: The command "dotnet -d publish-plugins bin/Debug/netcoreapp2.2/" exited with code 1.
Done building target "PreBuild" in project "Company.WebApp.csproj" -- FAILED.

Other people have reported same issue but they don't know it's the build tools: