Exemplo n.º 1
0
        private static IConfigurationRoot CreateConfiguration(IConfiguration configurationData,
                                                              IDotNetCliService dotNetCliService)
        {
            var info            = dotNetCliService.GetInfo();
            var msbuildSdksPath = Path.Combine(info.BasePath, "Sdks");

            var builder = new Microsoft.Extensions.Configuration.ConfigurationBuilder();

            if (configurationData != null)
            {
                builder.AddConfiguration(configurationData);
            }

            // We need to set the "UseLegacySdkResolver" for tests because
            // MSBuild's SDK resolver will not be able to locate the .NET Core SDKs
            // that we install locally in the ".dotnet" directory.
            // This property will cause the MSBuild project loader to set the
            // MSBuildSDKsPath environment variable to the correct path "Sdks" folder
            // within the appropriate .NET Core SDK.
            var msbuildProperties = new Dictionary <string, string>()
            {
                [$"MSBuild:{nameof(MSBuildOptions.UseLegacySdkResolver)}"] = "true",
                [$"MSBuild:{nameof(MSBuildOptions.MSBuildSDKsPath)}"]      = msbuildSdksPath
            };

            builder.AddInMemoryCollection(msbuildProperties);

            return(builder.Build());
        }
        private DotNetInfo GetDotNetInfo()
        {
            var workingDirectory = string.IsNullOrEmpty(_environment.SolutionFilePath)
                ? _environment.TargetDirectory
                : Path.GetDirectoryName(_environment.SolutionFilePath);

            return(_dotNetCli.GetInfo(workingDirectory));
        }