未验证 提交 81fedeba 编写于 作者: J Joey Robichaud 提交者: GitHub

Merge pull request #39597 from dotnet/merges/release/dev16.4-to-master

Merge release/dev16.4 to master
......@@ -331,6 +331,9 @@ function SetVisualStudioBootstrapperBuildArgs() {
# Core function for running our unit / integration tests tests
function TestUsingOptimizedRunner() {
# Capture the Path so we can revert it for integration tests
$originalPath = $env:PATH
# Tests need to locate .NET Core SDK
$dotnet = InitializeDotNetCli
......@@ -417,9 +420,26 @@ function TestUsingOptimizedRunner() {
$args += " $dll"
}
if ($testVsi) {
# Capture the Environment variables altered by `InitializeDotNetCli` so we can revert to them
$alteredDotNetMultiLevelLookup = $env:DOTNET_MULTILEVEL_LOOKUP
$alteredPath = $env:PATH
# Resolve runtime, shared framework, or SDK from other locations for integration tests
$env:DOTNET_MULTILEVEL_LOOKUP = $null
$env:PATH = $originalPath
}
try {
Exec-Console $runTests $args
} finally {
}
finally {
if ($testVsi) {
# Revert the environment variables to the state `InitializeDotNetCli` left them in
$env:DOTNET_MULTILEVEL_LOOKUP = $alteredDotNetMultiLevelLookup
$env:PATH = $alteredPath
}
Get-Process "xunit*" -ErrorAction SilentlyContinue | Stop-Process
if ($testIOperation) {
Remove-Item env:\ROSLYN_TEST_IOPERATION
......
......@@ -54,7 +54,7 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
: null;
var installerService = GetPackageInstallerService(document);
var packageSources = searchNuGetPackages && symbolSearchService != null && installerService != null
var packageSources = searchNuGetPackages && symbolSearchService != null && installerService?.IsEnabled(document.Project.Id) == true
? installerService.GetPackageSources()
: ImmutableArray<PackageSource>.Empty;
......
......@@ -40,7 +40,8 @@ static string DefaultNamespaceOfSingleProject(TestEnvironment environment)
[InlineData(LanguageVersion.Latest)]
[InlineData(LanguageVersion.LatestMajor)]
[InlineData(LanguageVersion.Preview)]
public void SetProperty_MaxSupportedLangVersion_CPS(LanguageVersion maxSupportedLangVersion)
[InlineData(null)]
public void SetProperty_MaxSupportedLangVersion_CPS(LanguageVersion? maxSupportedLangVersion)
{
var catalog = TestEnvironment.s_exportCatalog.Value
.WithParts(
......@@ -56,14 +57,47 @@ public void SetProperty_MaxSupportedLangVersion_CPS(LanguageVersion maxSupported
var project = environment.Workspace.CurrentSolution.Projects.Single();
var oldParseOptions = (CSharpParseOptions)project.ParseOptions;
cpsProject.SetProperty(AdditionalPropertyNames.MaxSupportedLangVersion, maxSupportedLangVersion.ToDisplayString());
cpsProject.SetProperty(AdditionalPropertyNames.MaxSupportedLangVersion, maxSupportedLangVersion?.ToDisplayString());
var canApply = environment.Workspace.CanApplyParseOptionChange(
oldParseOptions,
oldParseOptions.WithLanguageVersion(attemptedVersion),
project);
Assert.Equal(attemptedVersion <= maxSupportedLangVersion, canApply);
if (maxSupportedLangVersion.HasValue)
{
Assert.Equal(attemptedVersion <= maxSupportedLangVersion.Value, canApply);
}
else
{
Assert.True(canApply);
}
}
}
[WpfFact]
public void SetProperty_MaxSupportedLangVersion_CPS_NotSet()
{
var catalog = TestEnvironment.s_exportCatalog.Value
.WithParts(
typeof(CSharpParseOptionsChangingService));
const LanguageVersion attemptedVersion = LanguageVersion.CSharp8;
var factory = ExportProviderCache.GetOrCreateExportProviderFactory(catalog);
using (var environment = new TestEnvironment(exportProviderFactory: factory))
using (var cpsProject = CSharpHelpers.CreateCSharpCPSProject(environment, "Test"))
{
var project = environment.Workspace.CurrentSolution.Projects.Single();
var oldParseOptions = (CSharpParseOptions)project.ParseOptions;
var canApply = environment.Workspace.CanApplyParseOptionChange(
oldParseOptions,
oldParseOptions.WithLanguageVersion(attemptedVersion),
project);
Assert.True(canApply);
}
}
}
......
......@@ -4,10 +4,13 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Test.Utilities;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.LanguageServices.CSharp.ProjectSystemShim.Interop;
using Microsoft.VisualStudio.LanguageServices.CSharp.Utilities;
using Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem;
using Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.Interop;
using Microsoft.VisualStudio.LanguageServices.UnitTests.ProjectSystemShim.Framework;
using Microsoft.VisualStudio.Shell.Interop;
using Roslyn.Test.Utilities;
using Xunit;
......@@ -167,5 +170,80 @@ public void ProjectCompilationOutputsChange()
outputs = (CompilationOutputFilesWithImplicitPdbPath)environment.Workspace.GetCompilationOutputs(project.Test_VisualStudioProject.Id);
Assert.Equal(@"C:\a\3.dll", outputs.AssemblyFilePath);
}
[WpfTheory]
[InlineData(LanguageVersion.CSharp7_3)]
[InlineData(LanguageVersion.CSharp8)]
[InlineData(LanguageVersion.Latest)]
[InlineData(LanguageVersion.LatestMajor)]
[InlineData(LanguageVersion.Preview)]
[InlineData(null)]
public void SetProperty_MaxSupportedLangVersion(LanguageVersion? maxSupportedLangVersion)
{
var catalog = TestEnvironment.s_exportCatalog.Value
.WithParts(
typeof(CSharpParseOptionsChangingService));
var factory = ExportProviderCache.GetOrCreateExportProviderFactory(catalog);
using var environment = new TestEnvironment(exportProviderFactory: factory);
var hierarchy = environment.CreateHierarchy("CSharpProject", "Bin", projectRefPath: null, projectCapabilities: "CSharp");
var storage = Assert.IsAssignableFrom<IVsBuildPropertyStorage>(hierarchy);
Assert.True(ErrorHandler.Succeeded(
storage.SetPropertyValue(
"MaxSupportedLangVersion", null, (uint)_PersistStorageType.PST_PROJECT_FILE, maxSupportedLangVersion?.ToDisplayString())));
_ = CSharpHelpers.CreateCSharpProject(environment, "Test", hierarchy);
var project = environment.Workspace.CurrentSolution.Projects.Single();
var oldParseOptions = (CSharpParseOptions)project.ParseOptions;
const LanguageVersion attemptedVersion = LanguageVersion.CSharp8;
var canApply = environment.Workspace.CanApplyParseOptionChange(
oldParseOptions,
oldParseOptions.WithLanguageVersion(attemptedVersion),
project);
if (maxSupportedLangVersion.HasValue)
{
Assert.Equal(attemptedVersion <= maxSupportedLangVersion.Value, canApply);
}
else
{
Assert.True(canApply);
}
}
[WpfFact]
public void SetProperty_MaxSupportedLangVersion_NotSet()
{
var catalog = TestEnvironment.s_exportCatalog.Value
.WithParts(
typeof(CSharpParseOptionsChangingService));
var factory = ExportProviderCache.GetOrCreateExportProviderFactory(catalog);
using var environment = new TestEnvironment(exportProviderFactory: factory);
var hierarchy = environment.CreateHierarchy("CSharpProject", "Bin", projectRefPath: null, projectCapabilities: "CSharp");
var storage = Assert.IsAssignableFrom<IVsBuildPropertyStorage>(hierarchy);
_ = CSharpHelpers.CreateCSharpProject(environment, "Test", hierarchy);
var project = environment.Workspace.CurrentSolution.Projects.Single();
var oldParseOptions = (CSharpParseOptions)project.ParseOptions;
const LanguageVersion attemptedVersion = LanguageVersion.CSharp8;
var canApply = environment.Workspace.CanApplyParseOptionChange(
oldParseOptions,
oldParseOptions.WithLanguageVersion(attemptedVersion),
project);
Assert.True(canApply);
}
}
}
......@@ -101,6 +101,11 @@ internal abstract partial class AbstractLegacyProject : ForegroundThreadAffiniti
// (e.g. through a <defaultnamespace> msbuild property)
VisualStudioProject.DefaultNamespace = GetRootNamespacePropertyValue(hierarchy);
if (TryGetMaxLangVersionPropertyValue(hierarchy, out var maxLangVer))
{
VisualStudioProject.MaxLangVersion = maxLangVer;
}
Hierarchy = hierarchy;
ConnectHierarchyEvents();
RefreshBinOutputPath();
......@@ -391,5 +396,16 @@ private static string GetRootNamespacePropertyValue(IVsHierarchy hierarchy)
return null;
}
private static bool TryGetMaxLangVersionPropertyValue(IVsHierarchy hierarchy, out string maxLangVer)
{
if (!(hierarchy is IVsBuildPropertyStorage storage))
{
maxLangVer = null;
return false;
}
return ErrorHandler.Succeeded(storage.GetPropertyValue("MaxSupportedLangVersion", null, (uint)_PersistStorageType.PST_PROJECT_FILE, out maxLangVer));
}
}
}
......@@ -18,16 +18,16 @@ public CSharpUpgradeProject(VisualStudioInstanceFactory instanceFactory, ITestOu
{
}
private void InvokeFix()
private void InvokeFix(string version = "latest")
{
VisualStudio.Editor.SetText(@"
#error version:latest
VisualStudio.Editor.SetText(@$"
#error version:{version}
");
VisualStudio.Editor.Activate();
VisualStudio.Editor.PlaceCaret("version:latest");
VisualStudio.Editor.PlaceCaret($"version:{version}");
VisualStudio.Editor.InvokeCodeActionList();
VisualStudio.Editor.Verify.CodeAction("Upgrade this project to C# language version 'latest'", applyFix: true);
VisualStudio.Editor.Verify.CodeAction($"Upgrade this project to C# language version '{version}'", applyFix: true);
}
[WpfFact(Skip = "https://github.com/dotnet/roslyn/issues/38301"), Trait(Traits.Feature, Traits.Features.CodeActionsUpgradeProject)]
......@@ -49,10 +49,43 @@ public void LegacyProject_AllConfigurationsUpdated()
var project = new ProjectUtils.Project(ProjectName);
VisualStudio.SolutionExplorer.CreateSolution(SolutionName);
VisualStudio.SolutionExplorer.AddProject(project, WellKnownProjectTemplates.ClassLibrary, LanguageNames.CSharp);
VisualStudio.SolutionExplorer.AddCustomProject(project, ".csproj", $@"<?xml version=""1.0"" encoding=""utf-8""?>
<Project ToolsVersion=""15.0"" xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
<Import Project=""$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props"" Condition=""Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')"" />
<PropertyGroup>
<Configuration Condition=""'$(Configuration)' == ''"">Debug</Configuration>
<Platform Condition=""'$(Platform)' == ''"">x64</Platform>
<ProjectGuid>{{F4233BA4-A4CB-498B-BBC1-65A42206B1BA}}</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>{ProjectName}</RootNamespace>
<AssemblyName>{ProjectName}</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<LangVersion>7.0</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=""'$(Configuration)|$(Platform)' == 'Debug|x86'"">
<OutputPath>bin\x86\Debug\</OutputPath>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=""'$(Configuration)|$(Platform)' == 'Release|x86'"">
<OutputPath>bin\x86\Release\</OutputPath>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=""'$(Configuration)|$(Platform)' == 'Debug|x64'"">
<OutputPath>bin\x64\Debug\</OutputPath>
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=""'$(Configuration)|$(Platform)' == 'Release|x64'"">
<OutputPath>bin\x64\Release\</OutputPath>
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
<ItemGroup>
</ItemGroup>
<Import Project=""$(MSBuildToolsPath)\Microsoft.CSharp.targets"" />
</Project>");
VisualStudio.SolutionExplorer.AddFile(project, "C.cs", open: true);
InvokeFix();
VerifyPropertyInEachConfiguration(GetProjectFileElement(project), "LangVersion", "latest");
InvokeFix(version: "7.3");
VerifyPropertyInEachConfiguration(GetProjectFileElement(project), "LangVersion", "7.3");
}
[WorkItem(23342, "https://github.com/dotnet/roslyn/issues/23342")]
......@@ -77,6 +110,7 @@ public void LegacyProject_MultiplePlatforms_AllConfigurationsUpdated()
<PropertyGroup Condition=""'$(Configuration)|$(Platform)' == 'Debug|x86'"">
<OutputPath>bin\x86\Debug\</OutputPath>
<PlatformTarget>x86</PlatformTarget>
<LangVersion>7.2</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=""'$(Configuration)|$(Platform)' == 'Release|x86'"">
<OutputPath>bin\x86\Release\</OutputPath>
......@@ -91,6 +125,7 @@ public void LegacyProject_MultiplePlatforms_AllConfigurationsUpdated()
<PropertyGroup Condition=""'$(Configuration)|$(Platform)' == 'Release|x64'"">
<OutputPath>bin\x64\Release\</OutputPath>
<PlatformTarget>x64</PlatformTarget>
<LangVersion>7.1</LangVersion>
</PropertyGroup>
<ItemGroup>
</ItemGroup>
......@@ -99,8 +134,8 @@ public void LegacyProject_MultiplePlatforms_AllConfigurationsUpdated()
VisualStudio.SolutionExplorer.AddFile(project, "C.cs", open: true);
InvokeFix();
VerifyPropertyInEachConfiguration(GetProjectFileElement(project), "LangVersion", "latest");
InvokeFix(version: "7.3");
VerifyPropertyInEachConfiguration(GetProjectFileElement(project), "LangVersion", "7.3");
}
}
}
......@@ -19,6 +19,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.ProjectSystemShim.Fr
Private _projectName As String
Private _projectBinPath As String
Private _maxSupportedLangVer As String
Private ReadOnly _projectRefPath As String
Private ReadOnly _projectCapabilities As String
Private ReadOnly _projectMock As Mock(Of EnvDTE.Project) = New Mock(Of EnvDTE.Project)(MockBehavior.Strict)
......@@ -330,6 +331,9 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.ProjectSystemShim.Fr
ElseIf pszPropName = "TargetRefPath" Then
pbstrPropValue = _projectRefPath
Return VSConstants.S_OK
ElseIf pszPropName = "MaxSupportedLangVersion" Then
pbstrPropValue = _maxSupportedLangVer
Return VSConstants.S_OK
End If
Throw New NotSupportedException($"{NameOf(MockHierarchy)}.{NameOf(GetPropertyValue)} does not support reading {pszPropName}.")
......@@ -342,6 +346,9 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.ProjectSystemShim.Fr
ElseIf pszPropName = "TargetFileName" Then
_projectName = PathUtilities.GetFileName(pszPropValue, includeExtension:=False)
Return VSConstants.S_OK
ElseIf pszPropName = "MaxSupportedLangVersion" Then
_maxSupportedLangVer = pszPropValue
Return VSConstants.S_OK
End If
Throw New NotImplementedException()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册