Skip to content
This repository has been archived by the owner on May 17, 2024. It is now read-only.

Adds VB support for Unit Tests and WPF #390

Merged
merged 4 commits into from
Mar 27, 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
11 changes: 9 additions & 2 deletions src/MSBuild.Abstractions/MSBuildConversionWorkspace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public MSBuildConversionWorkspace(ImmutableArray<string> paths, bool noBackup, s
RemoveTargetsNotLoadableByNETSDKMSBuild(path);

var root = new MSBuildProjectRootElement(ProjectRootElement.Open(path, collection, preserveFormatting: true));
if (IsSupportedProjectType(root, forceWeb))
if (IsSupportedProjectType(root, forceWeb, keepCurrentTFMs))
{

var configurations = DetermineConfigurations(root);
Expand Down Expand Up @@ -305,7 +305,7 @@ private ProjectStyle GetProjectStyle(IProjectRootElement projectRootElement)
}
}

private bool IsSupportedProjectType(IProjectRootElement root, bool forceWeb)
private bool IsSupportedProjectType(IProjectRootElement root, bool forceWeb, bool keepCurrentTFMs)
{
if (root.Sdk.ContainsIgnoreCase(MSBuildFacts.DefaultSDKAttribute))
{
Expand All @@ -329,6 +329,13 @@ private bool IsSupportedProjectType(IProjectRootElement root, bool forceWeb)
Console.WriteLine($"{root.FullPath} contains an App.config file. App.config is replaced by appsettings.json in .NET Core. You will need to delete App.config and migrate to appsettings.json if it's applicable to your project.");
}

if (!keepCurrentTFMs
&& root.PropertyGroups.Any(pg => pg.Properties.Any(ProjectPropertyHelpers.IsVisualBasicProject))
&& root.ItemGroups.Any(ig => ig.Items.Any(ProjectItemHelpers.IsReferencingSettingsSingleFileGenerator)))
{
Console.WriteLine($"{root.FullPath} uses code generators which will not be handled by try-convert. You can edit your vbproj to add support or remove these dependencies.");
}
KSchlobohm marked this conversation as resolved.
Show resolved Hide resolved

// Lots of wild old project types have project type guids that the old project system uses to light things up!
// Also some references that are incompatible.
var projectType = GetProjectSupportType(root);
Expand Down
7 changes: 7 additions & 0 deletions src/MSBuild.Abstractions/ProjectItemHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,12 @@ public static bool IsExplicitValueTupleReferenceThatCanBeRemoved(ProjectItemElem
public static bool IsReferencingSystemWeb(ProjectItemElement item) =>
item.ElementName.Equals(MSBuildFacts.MSBuildReferenceName, StringComparison.OrdinalIgnoreCase)
&& item.Include.Equals(MSBuildFacts.SystemWebReferenceName, StringComparison.OrdinalIgnoreCase);

public static bool IsReferencingSettingsSingleFileGenerator(ProjectItemElement item)
{
var metadata = item.Children.FirstOrDefault(child => MSBuildFacts.EmbeddedResourceGeneratorProperty.Equals(child.ElementName, StringComparison.Ordinal) ) as ProjectMetadataElement;
return metadata is null ? false : metadata.Value.Equals(MSBuildFacts.SettingsSingleFileGenerator, StringComparison.Ordinal);
}

}
}
4 changes: 4 additions & 0 deletions src/MSBuild.Abstractions/ProjectPropertyHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,5 +162,9 @@ public static bool IsExeOutputType(ProjectPropertyElement prop) =>
public static bool IsWinExeOutputType(ProjectPropertyElement prop) =>
prop.ElementName.Equals(MSBuildFacts.OutputTypeNodeName, StringComparison.OrdinalIgnoreCase)
&& prop.Value.Equals(MSBuildFacts.WinExeOutputType, StringComparison.OrdinalIgnoreCase);


public static bool IsVisualBasicProject(ProjectPropertyElement prop) =>
IsProjectTypeGuidsNode(prop) && prop.Value.Split(';').Any(guidString => Guid.Parse(guidString) == MSBuildFacts.LanguageProjectTypeVisualBasic);
}
}
1 change: 1 addition & 0 deletions src/MSBuild.Conversion.Facts/DesktopFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public static class DesktopFacts
);

public static ImmutableArray<Guid> KnownSupportedDesktopProjectTypeGuids => ImmutableArray.Create(
MSBuildFacts.LanguageProjectTypeVisualBasic, // VB.NET
Guid.Parse("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"), // C#
Guid.Parse("{60DC8134-EBA5-43B8-BCC9-BB4BC16C2548}") // WPF
);
Expand Down
8 changes: 6 additions & 2 deletions src/MSBuild.Conversion.Facts/MSBuildFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,12 @@ public static class MSBuildFacts
"ProjectReference"
);

public static Guid LanguageProjectTypeVisualBasic => Guid.Parse("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the guid that was labeled F# previously. What that comment wrong or do we need to swap this guid?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the comment was wrong.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if I recall, this was pulled from a legacy F# project. Interesting!


public static ImmutableArray<Guid> LanguageProjectTypeGuids => ImmutableArray.Create(
Guid.Parse("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"), // C#
Guid.Parse("{F2A71F9B-5D33-465A-A702-920D77279786}"), // VB.NET
Guid.Parse("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") // F#
LanguageProjectTypeVisualBasic, // VB.NET
Guid.Parse("{F2A71F9B-5D33-465A-A702-920D77279786}") // F#
);

public const string DefaultSDKAttribute = "Microsoft.NET.Sdk";
Expand Down Expand Up @@ -296,5 +298,7 @@ public static class MSBuildFacts
public const string Net5 = "net5.0";
public const string Net5Windows = "net5.0-windows";
public const string AppConfig = "App.config";
public const string EmbeddedResourceGeneratorProperty = "Generator";
public const string SettingsSingleFileGenerator = "SettingsSingleFileGenerator";
}
}
1 change: 1 addition & 0 deletions src/MSBuild.Conversion.Facts/MSTestFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public static class MSTestFacts
);

public static ImmutableArray<Guid> KnownOldMSTestProjectTypeGuids => ImmutableArray.Create(
MSBuildFacts.LanguageProjectTypeVisualBasic, // VB.NET
Guid.Parse("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"), // C#
Guid.Parse("{3AC096D0-A1C2-E12C-1390-A8335801FDAB}") // Test
);
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,10 @@
<?xml version="1.0" encoding="utf-8"?>
<MyApplicationData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<MySubMain>false</MySubMain>
<SingleInstance>false</SingleInstance>
<ShutdownMode>0</ShutdownMode>
<EnableVisualStyles>true</EnableVisualStyles>
<AuthenticationMode>0</AuthenticationMode>
<ApplicationType>1</ApplicationType>
<SaveMySettingsOnExit>true</SaveMySettingsOnExit>
</MyApplicationData>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Imports System
KSchlobohm marked this conversation as resolved.
Show resolved Hide resolved
Imports System.Reflection
Imports System.Runtime.InteropServices

<Assembly: AssemblyTitle("UnitTestProject1")>
<Assembly: AssemblyDescription("")>
<Assembly: AssemblyCompany("")>
<Assembly: AssemblyProduct("UnitTestProject1")>
<Assembly: AssemblyCopyright("Copyright © 2021")>
<Assembly: AssemblyTrademark("")>

<Assembly: ComVisible(False)>

<Assembly: Guid("8e844673-9877-45d2-a79e-8bf48431e9c7")>

' <Assembly: AssemblyVersion("1.0.*")>
<Assembly: AssemblyVersion("1.0.0.0")>
<Assembly: AssemblyFileVersion("1.0.0.0")>

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

117 changes: 117 additions & 0 deletions tests/TestData/SmokeTests.LegacyMSTestVB/My Project/Resources.resx
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<?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.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: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" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
</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" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
</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=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

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

Loading