Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add commandline to chose VS version #753

Merged
merged 4 commits into from
Jul 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

### Changed
- Updated try-convert tool version from `0.7.226301` to `0.9.232202`

### Added
- Added command line argument to select VS version (`--vs-path`) in cases where multiple are installed [#753](https://github.com/dotnet/upgrade-assistant/pull/753)
- Added analyzers for identifying common namespaces, types, and members that require manual fixup and will produce diagnostics with links to relevant docs. The list of APIs identified by the analyzer can be expanded by adding to DefaultApiAlerts.json or by adding a .apitargets file to a project's additional files. [#685](https://github.com/dotnet/upgrade-assistant/pull/685)
- Link to survey [#735](https://github.com/dotnet/upgrade-assistant/pull/735)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ private class ExtensionOptions : IUpgradeAssistantOptions
public IReadOnlyCollection<string> Extension => Array.Empty<string>();

public IEnumerable<AdditionalOption> AdditionalOptions => Enumerable.Empty<AdditionalOption>();

public DirectoryInfo? VSPath { get; set; }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,9 @@ private async Task RunStepAsync(IUpgradeContext context, UpgradeStep step, Cance
else
{
_logger.LogWarning("Upgrade process was canceled. Quitting....");
return;
}

token.ThrowIfCancellationRequested();
}

private async ValueTask<bool> ExecuteAndTimeCommand(IUpgradeContext context, UpgradeStep step, UpgradeCommand command, CancellationToken token)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public UpgradeAssistantCommand(string name)
AddOption(new Option<IReadOnlyCollection<string>>(new[] { "--entry-point", "-e" }, "Provides the entry-point project to start the upgrade process. This may include globbing patterns such as '*' for match."));
AddOption(new Option<UpgradeTarget>(new[] { "--target-tfm-support" }, "Select if you would like the Long Term Support (LTS), Current, or Preview TFM. See https://dotnet.microsoft.com/platform/support/policy/dotnet-core for details for what these mean."));
AddOption(new Option<bool>(new[] { "--ignore-unsupported-features" }, "Acknowledges that upgrade-assistant will not be able to completely upgrade a project. This indicates that the solution must be redesigned (e.g. consider Blazor to replace Web Forms)."));
AddOption(new Option<DirectoryInfo>(new[] { "--vs-path" }, "Path to a VS install directory to be used for %VSINSTALLDIR%. If not provided, the latest installed version will be used."));
}

protected class CommandOptions : IUpgradeAssistantOptions
Expand All @@ -44,6 +45,8 @@ protected class CommandOptions : IUpgradeAssistantOptions
public UpgradeTarget TargetTfmSupport { get; set; } = UpgradeTarget.Current;

public IEnumerable<AdditionalOption> AdditionalOptions => Option.ParseOptions();

public DirectoryInfo? VSPath { get; set; }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@ public interface IUpgradeAssistantOptions
IReadOnlyCollection<string> Extension { get; }

IEnumerable<AdditionalOption> AdditionalOptions { get; }

DirectoryInfo? VSPath { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public static IHostBuilder UseUpgradeAssistant<TApp>(this IHostBuilder host, IUp
services.AddMsBuild(optionss =>
{
optionss.InputPath = upgradeOptions.Project.FullName;
optionss.VisualStudioPath = upgradeOptions.VSPath?.FullName;
});

services.AddNuGet(optionss =>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema

Version 2.0

The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.

Example:

... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>

There are any number of "resheader" rows that contain simple
name/value pairs.

Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.

The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:

Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.

mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.

mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.

mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="InvalidProjectError" xml:space="preserve">
<value>Could not load project. Please ensure the selected VS instance has the correct workloads installed for your projects. If Upgrade Assistant selected the incorrect VS version, please pass the argument --vs-path with the appropriate path. You can see the Visual Studio instances searched by running with the --verbose flag.</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Build.Exceptions;
using Microsoft.CodeAnalysis;
using Microsoft.Extensions.Logging;

Expand Down Expand Up @@ -67,7 +68,20 @@ private static Language ParseLanguageByProjectFileExtension(string extension)
_ => Language.Unknown
};

public MBuild.Project Project => Context.ProjectCollection.LoadProject(FileInfo.FullName);
public MBuild.Project Project
{
get
{
try
{
return Context.ProjectCollection.LoadProject(FileInfo.FullName);
}
catch (InvalidProjectFileException ex)
{
throw new UpgradeException(LocalizedStrings.InvalidProjectError, ex);
}
}
}

public ProjectOutputType OutputType =>
ProjectRoot.Properties.FirstOrDefault(p => p.Name.Equals(MSBuildConstants.OutputTypePropertyName, StringComparison.OrdinalIgnoreCase))?.Value switch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,17 @@
<ProjectReference Include="..\Microsoft.DotNet.UpgradeAssistant.Telemetry\Microsoft.DotNet.UpgradeAssistant.Telemetry.csproj" />
<ProjectReference Include="..\Microsoft.DotNet.UpgradeAssistant\Microsoft.DotNet.UpgradeAssistant.csproj" />
</ItemGroup>
<ItemGroup>
<Compile Update="LocalizedStrings.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>LocalizedStrings.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="LocalizedStrings.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>LocalizedStrings.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.IO;
using System.Runtime.InteropServices;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Microsoft.VisualStudio.Setup.Configuration;

namespace Microsoft.DotNet.UpgradeAssistant.MSBuild
Expand All @@ -21,15 +22,23 @@ internal class VisualStudioFinder : IVisualStudioFinder
{
private const int REGDB_E_CLASSNOTREG = unchecked((int)0x80040154);

private readonly IOptions<WorkspaceOptions> _options;
private readonly ILogger<VisualStudioFinder> _logger;

public VisualStudioFinder(ILogger<VisualStudioFinder> logger)
public VisualStudioFinder(IOptions<WorkspaceOptions> options, ILogger<VisualStudioFinder> logger)
{
_logger = logger;
_options = options ?? throw new ArgumentNullException(nameof(options));
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
}

public string? GetLatestVisualStudioPath()
{
if (_options.Value.VisualStudioPath is string expectedPath)
{
_logger.LogInformation("Using supplied path for Visual Studio [Path]", expectedPath);
return expectedPath;
}

var latest = GetLatestPath();

if (latest is null)
Expand All @@ -43,19 +52,19 @@ public VisualStudioFinder(ILogger<VisualStudioFinder> logger)

if (Directory.Exists(installation))
{
_logger.LogDebug("Found Visual Studio {VsVersion} at {VsPath}", version, installation);
_logger.LogDebug("Using Visual Studio v{VsVersion} [{VsPath}]", version, installation);

return installation;
}
else
{
_logger.LogInformation("Found Visual Studio {VsVersion}, but directory '{VsPath}' does not exist.", version, installation);
_logger.LogWarning("Found Visual Studio {VsVersion}, but directory '{VsPath}' does not exist.", version, installation);

return null;
}
}

private static ISetupInstance2? GetLatestPath()
private ISetupInstance2? GetLatestPath()
{
var result = default(ISetupInstance2);
var resultVersion = new Version(0, 0);
Expand Down Expand Up @@ -100,10 +109,15 @@ public VisualStudioFinder(ILogger<VisualStudioFinder> logger)
}
}

if (instanceHasMSBuild && instance is not null && version > resultVersion)
if (instanceHasMSBuild && instance is not null)
{
result = instance;
resultVersion = version;
_logger.LogInformation("Found Visual Studio v{Version} [{Path}]", version, instance.GetInstallationPath());

if (version > resultVersion)
{
result = instance;
resultVersion = version;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ public class WorkspaceOptions
{
[Required]
public string InputPath { get; set; } = null!;

public string? VisualStudioPath { get; set; }
}
}
Loading