Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
02f1e31
Enable Mono CI builds (#1481)
radical Dec 19, 2016
9f13df6
Revert "Enable Mono CI builds"
rainersigwald Jan 25, 2017
d7bf820
Merge branch 'master' of github.com:Microsoft/msbuild
Oct 2, 2018
90d20bf
First step at porting StronglyTypedResourceBuilder
wjk Oct 2, 2018
54dc675
Fix build under FEATURE_CODEDOM && .NET Core
wjk Oct 2, 2018
3f80285
Update StronglyTypedResourceBuilder to operate on type name strings
wjk Oct 2, 2018
acdea2e
Fix non-string resource handling
wjk Oct 2, 2018
f45af2a
Fix indentation error
wjk Oct 2, 2018
6a3e243
Fix handling of ResXFileRef objects
wjk Oct 3, 2018
0242f82
Update STRB to work on types as well as type names
wjk Oct 5, 2018
3660242
Fix failing unit test
wjk Oct 6, 2018
9348e5b
Use StringComparison.Ordinal
iSazonov Nov 13, 2018
be56e2c
Use StringComparison.Ordinal
iSazonov Nov 13, 2018
8f448bc
Fix build
wjk Nov 13, 2018
423cfc1
Don't print out non-string values in the STR file
wjk Nov 13, 2018
b60a54a
Merge branch 'master' into resgen-improvements
wjk Nov 13, 2018
6dc39a1
Address PR feedback
wjk Nov 14, 2018
b118be6
Address more PR feedback
wjk Nov 14, 2018
bc0f888
Use typeof(object) when the value is null
wjk Nov 14, 2018
e45c285
Revert "Use typeof(object) when the value is null"
wjk Nov 14, 2018
c5e116f
Merge branch 'master' of github.com:Microsoft/msbuild
wjk Nov 14, 2018
afe12c7
Merge branch 'master' into resgen-improvements
wjk Nov 14, 2018
7e54b77
Reinstate "Use typeof(object) when the value is null"
wjk Nov 15, 2018
5414146
Fix failing unit tests
wjk Nov 15, 2018
1143d53
Fix test failure
wjk Nov 15, 2018
019bff0
Enable FEATURE_CODEDOM only for Tasks and its unit tests
Nov 15, 2018
06e1bc2
Catch appropriate exception for .NET Core CodeDom
Nov 15, 2018
57d9011
Fix unit test on non-Windows platform
Nov 15, 2018
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
3 changes: 2 additions & 1 deletion build/Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<PackageReference Update="System.Collections.Concurrent" Version="4.3.0" />
<!-- Update binding redirect in app.config and app.amd64.config when changing this -->
<PackageReference Update="System.Collections.Immutable" Version="1.5.0" />
<PackageReference Update="System.Configuration.ConfigurationManager" Version="4.5.0" />
<PackageReference Update="System.Diagnostics.TraceSource" Version="4.0.0" />
<PackageReference Update="System.IO.Compression" Version="4.3.0" />
<PackageReference Update="System.IO.FileSystem.Primitives" Version="4.3.0" />
Expand All @@ -42,7 +43,7 @@
<PackageReference Update="System.Runtime.InteropServices.RuntimeInformation" Version="4.3.0" />
<PackageReference Update="System.Runtime.Loader" Version="4.0.0" />
<PackageReference Update="System.Runtime.Serialization.Primitives" Version="4.1.1" />
<PackageReference Update="System.Security.Principal.Windows" Version="4.3.0" />
<PackageReference Update="System.Security.Principal.Windows" Version="4.5.0" />
<PackageReference Update="System.Text.Encoding.CodePages" Version="4.0.1" />

<!-- Update binding redirect in app.config and app.amd64.config when changing this -->
Expand Down
1 change: 1 addition & 0 deletions src/Directory.BeforeCommon.targets
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
<DefineConstants>$(DefineConstants);FEATURE_WORKINGSET</DefineConstants>
<DefineConstants Condition="'$(MonoBuild)' != 'true' and '$(MachineIndependentBuild)' != 'true'">$(DefineConstants);FEATURE_VISUALSTUDIOSETUP</DefineConstants>
<DefineConstants>$(DefineConstants);FEATURE_MSCOREE</DefineConstants>
<DefineConstants>$(DefineConstants);FEATURE_WINFORMS_RESX</DefineConstants>
</PropertyGroup>

<PropertyGroup>
Expand Down
16 changes: 16 additions & 0 deletions src/Tasks.UnitTests/GenerateResource_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,9 @@ public void StronglyTypedResources()
Assert.Equal(Path.GetExtension(resourcesFile), ".resources");
resourcesFile = t.FilesWritten[0].ItemSpec;
Assert.Equal(Path.GetExtension(resourcesFile), ".resources");
#if FEATURE_RESGENCACHE
Utilities.AssertStateFileWasWritten(t);
#endif
// Files written should contain STR class file
string stronglyTypedFileName = Path.ChangeExtension(t.Sources[0].ItemSpec, ".cs");
Assert.Equal(t.FilesWritten[2].ItemSpec, stronglyTypedFileName);
Expand Down Expand Up @@ -910,7 +912,9 @@ public void StronglyTypedResourcesUpToDate()
resourcesFile = t.FilesWritten[0].ItemSpec;
Assert.Equal(Path.GetExtension(resourcesFile), ".resources");

#if FEATURE_RESGENCACHE
Utilities.AssertStateFileWasWritten(t);
#endif
// Files written should contain STR class file
string stronglyTypedFileName = Path.ChangeExtension(t.Sources[0].ItemSpec, ".cs");
Assert.Equal(t.FilesWritten[2].ItemSpec, stronglyTypedFileName);
Expand Down Expand Up @@ -940,7 +944,9 @@ public void StronglyTypedResourcesUpToDate()
Assert.Equal(t2.OutputResources[0].ItemSpec, resourcesFile);
Assert.Equal(t2.FilesWritten[0].ItemSpec, resourcesFile);

#if FEATURE_RESGENCACHE
Utilities.AssertStateFileWasWritten(t2);
#endif
Assert.Equal(t2.FilesWritten[2].ItemSpec, Path.ChangeExtension(t2.Sources[0].ItemSpec, ".cs"));
}
finally
Expand Down Expand Up @@ -1144,7 +1150,9 @@ public void StronglyTypedResourcesVB()
resourcesFile = t.FilesWritten[0].ItemSpec;
Assert.Equal(Path.GetExtension(resourcesFile), ".resources");

#if FEATURE_RESGENCACHE
Utilities.AssertStateFileWasWritten(t);
#endif
Assert.True(File.Exists(stronglyTypedFileName));

Utilities.AssertLogContainsResource(t, "GenerateResource.ProcessingFile", textFile, resourcesFile);
Expand Down Expand Up @@ -1200,7 +1208,9 @@ public void StronglyTypedResourcesWithoutNamespaceOrClassOrFilename()
resourcesFile = t.FilesWritten[0].ItemSpec;
Assert.Equal(Path.GetExtension(resourcesFile), ".resources");

#if FEATURE_RESGENCACHE
Utilities.AssertStateFileWasWritten(t);
#endif

// Should have defaulted the STR filename to the bare output resource name + ".cs"
string STRfile = Path.ChangeExtension(t.Sources[0].ItemSpec, ".cs");
Expand Down Expand Up @@ -1922,7 +1932,9 @@ public void StronglyTypedClassName()
// Verify class was public, as we specified
Assert.True(File.ReadAllText(t.StronglyTypedFileName).Contains("public class " + t.StronglyTypedClassName));

#if FEATURE_RESGENCACHE
Utilities.AssertStateFileWasWritten(t);
#endif
}
finally
{
Expand Down Expand Up @@ -1970,7 +1982,9 @@ public void StronglyTypedFileName()
Assert.Equal(t.StronglyTypedFileName, Path.ChangeExtension(t.Sources[0].ItemSpec, ".cs"));
Assert.True(File.Exists(t.StronglyTypedFileName));

#if FEATURE_RESGENCACHE
Utilities.AssertStateFileWasWritten(t);
#endif

// Verify class was internal, since we didn't specify a preference
Assert.True(File.ReadAllText(t.StronglyTypedFileName).Contains("internal class " + t.StronglyTypedClassName));
Expand Down Expand Up @@ -3628,7 +3642,9 @@ public static void STRNamespaceTestHelper(string strLanguage, string resourcesNa
resourcesFile = t.FilesWritten[0].ItemSpec;
Assert.Equal(Path.GetExtension(resourcesFile), ".resources");

#if FEATURE_RESGENCACHE
Utilities.AssertStateFileWasWritten(t);
#endif

// Files written should contain STR class file
Assert.Equal(Path.ChangeExtension(t.Sources[0].ItemSpec, codeFileExtension), t.StronglyTypedFileName);
Expand Down
2 changes: 1 addition & 1 deletion src/Tasks.UnitTests/Microsoft.Build.Tasks.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<AssemblyName>Microsoft.Build.Tasks.UnitTests</AssemblyName>
<IsTestProject>true</IsTestProject>
<DefineConstants>$(DefineConstants);MICROSOFT_BUILD_TASKS_UNITTESTS</DefineConstants>
<DefineConstants>$(DefineConstants);MICROSOFT_BUILD_TASKS_UNITTESTS;FEATURE_CODEDOM</DefineConstants>
</PropertyGroup>

<ItemGroup>
Expand Down
4 changes: 0 additions & 4 deletions src/Tasks.UnitTests/WriteCodeFragment_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -464,13 +464,9 @@ public void MultilineAttributeCSharp()
private static readonly string WindowsNewLine = $"{VBCarriageReturn}&{VBLineFeed}";

public static readonly string VBLineSeparator =
#if FEATURE_CODEDOM
WindowsNewLine;
#else
NativeMethodsShared.IsWindows
? WindowsNewLine
: VBLineFeed;
#endif

/// <summary>
/// Multi line argument values should cause a verbatim string to be used
Expand Down
49 changes: 40 additions & 9 deletions src/Tasks/GenerateResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@
using System.CodeDom.Compiler;
using System.Xml;
using System.Runtime.InteropServices;
#if FEATURE_SYSTEM_CONFIGURATION
using System.Configuration;
#endif
using System.Security;
#if FEATURE_RESX_RESOURCE_READER
using System.ComponentModel.Design;
Expand Down Expand Up @@ -3054,8 +3052,26 @@ private void ReadResources(String filename, bool shouldUseSourcePath, String out
foreach (XElement dataElem in doc.Element("root").Elements("data"))
{
string name = dataElem.Attribute("name").Value;
string typeName = dataElem.Attribute("type")?.Value;
string value = dataElem.Element("value").Value;
AddResource(reader, name, value, filename);

if (typeName != null)
{
int pos = typeName.IndexOf(',');
if (pos > 0) typeName = typeName.Substring(0, pos); // strip off the assembly name or alias, if any
}

if (typeName == "System.Resources.ResXFileRef")
{
// The "real" type of a ResXFileRef is embedded in the value.
var pos = value.IndexOf(';');
if (pos > 0) typeName = value.Substring(pos + 1);

pos = typeName.IndexOf(',');
if (pos > 0) typeName = typeName.Substring(0, pos);
}

AddResource(reader, name, value, filename, typeName);
}
}
break;
Expand Down Expand Up @@ -3444,18 +3460,23 @@ public static bool TryCreateCodeDomProvider(TaskLoggingHelper logger, string str
{
provider = CodeDomProvider.CreateProvider(stronglyTypedLanguage);
}
#if FEATURE_SYSTEM_CONFIGURATION
Copy link
Contributor

Choose a reason for hiding this comment

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

Elsewhere you still have configuration #if'ed out. Does CodeDomProvider actually throw configuration exception on .NET Core? I think we should avoid adding a dependency on it if it's not needed.

catch (ConfigurationException e)
{
logger.LogErrorWithCodeFromResources("GenerateResource.STRCodeDomProviderFailed", stronglyTypedLanguage, e.Message);
return false;
}
#endif
catch (SecurityException e)
{
logger.LogErrorWithCodeFromResources("GenerateResource.STRCodeDomProviderFailed", stronglyTypedLanguage, e.Message);
return false;
}
catch (SystemException e)
{
// The actual exception type thrown (System.CodeDom.Compiler.CodeDomProvider.ConfigurationErrorsException)
// is private to the CodeDomProvider class, but it inherits from SystemException.
logger.LogErrorWithCodeFromResources("GenerateResource.STRCodeDomProviderFailed", stronglyTypedLanguage, e.Message);
return false;
}

return provider != null;
}
Expand Down Expand Up @@ -3739,7 +3760,8 @@ private void WriteTextResources(ReaderInfo reader, String fileName)
/// <param name="inputFileName">Input file for messages</param>
/// <param name="lineNumber">Line number for messages</param>
/// <param name="linePosition">Column number for messages</param>
private void AddResource(ReaderInfo reader, string name, object value, String inputFileName, int lineNumber, int linePosition)
/// <param name="customTypeName">Type name for custom object type</param>
private void AddResource(ReaderInfo reader, string name, object value, String inputFileName, int lineNumber, int linePosition, string customTypeName = null)
{
Entry entry = new Entry(name, value);

Expand All @@ -3750,7 +3772,16 @@ private void AddResource(ReaderInfo reader, string name, object value, String in
}

reader.resources.Add(entry);
reader.resourcesHashTable.Add(name, value);
if (customTypeName != null)
{
reader.resourcesHashTable.Add(name, new StronglyTypedResourceBuilder.ResourceData(customTypeName, value));
}
else
{
Type valueType = typeof(object);
if (value != null) valueType = value.GetType();
reader.resourcesHashTable.Add(name, new StronglyTypedResourceBuilder.ResourceData(valueType, value));
}
}

/// <summary>
Expand All @@ -3759,9 +3790,9 @@ private void AddResource(ReaderInfo reader, string name, object value, String in
/// <param name="name">Resource name</param>
/// <param name="value">Resource value</param>
/// <param name="inputFileName">Input file for messages</param>
private void AddResource(ReaderInfo reader, string name, object value, String inputFileName)
private void AddResource(ReaderInfo reader, string name, object value, String inputFileName, string customTypeName = null)
{
AddResource(reader, name, value, inputFileName, 0, 0);
AddResource(reader, name, value, inputFileName, 0, 0, customTypeName);
}

internal sealed class ReaderInfo
Expand Down
12 changes: 7 additions & 5 deletions src/Tasks/Microsoft.Build.Tasks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<GenerateReferenceAssemblySources>true</GenerateReferenceAssemblySources>
<AssemblyName>Microsoft.Build.Tasks.Core</AssemblyName>
<RootNamespace>Microsoft.Build.Tasks</RootNamespace>
<DefineConstants>$(DefineConstants);MICROSOFT_BUILD_TASKS</DefineConstants>
<DefineConstants>$(DefineConstants);MICROSOFT_BUILD_TASKS;FEATURE_CODEDOM</DefineConstants>
<CreateTlb>true</CreateTlb>
<IsPackable>true</IsPackable>
<Description>This package contains the $(MSBuildProjectName) assembly which implements the commonly used tasks of MSBuild.</Description>
Expand Down Expand Up @@ -482,6 +482,7 @@
<Compile Include="RoslynCodeTaskFactory\RoslynCodeTaskFactoryCodeType.cs" />
<Compile Include="RoslynCodeTaskFactory\RoslynCodeTaskFactoryCompilers.cs" />
<Compile Include="RoslynCodeTaskFactory\RoslynCodeTaskFactoryTaskInfo.cs" />
<Compile Include="System.Design.cs" />
<Compile Include="TaskExtension.cs">
<ExcludeFromStyleCop>true</ExcludeFromStyleCop>
</Compile>
Expand Down Expand Up @@ -512,6 +513,9 @@
<Compile Include="SystemState.cs" />
<Compile Include="DependencyFile.cs" />
<Compile Include="ZipDirectory.cs" />
<Compile Include="system.design\stronglytypedresourcebuilder.cs">
<ExcludeFromStyleCop>true</ExcludeFromStyleCop>
</Compile>
</ItemGroup>
<ItemGroup Condition="$(TargetFrameworkIdentifier) == '.NETFramework'">
<Compile Include="Al.cs">
Expand Down Expand Up @@ -633,16 +637,12 @@
<Compile Include="SignFile.cs" Condition="'$(MonoBuild)' != 'true'">
<ExcludeFromStyleCop>true</ExcludeFromStyleCop>
</Compile>
<Compile Include="system.design\stronglytypedresourcebuilder.cs">
<ExcludeFromStyleCop>true</ExcludeFromStyleCop>
</Compile>
<Compile Include="StrongNameException.cs">
<ExcludeFromStyleCop>true</ExcludeFromStyleCop>
</Compile>
<Compile Include="StrongNameUtils.cs">
<ExcludeFromStyleCop>true</ExcludeFromStyleCop>
</Compile>
<Compile Include="System.Design.cs" />
<Compile Include="TlbImp.cs" />
<Compile Include="TlbReference.cs">
<ExcludeFromStyleCop>true</ExcludeFromStyleCop>
Expand Down Expand Up @@ -981,6 +981,7 @@

<ItemGroup Condition="'$(TargetFrameworkIdentifier)' != '.NETFramework'">
<PackageReference Include="System.CodeDom" />
<PackageReference Include="System.Configuration.ConfigurationManager" />
<PackageReference Include="System.Linq.Parallel" />
<PackageReference Include="System.Net.Http" />
<PackageReference Include="System.Reflection.Metadata" />
Expand All @@ -991,6 +992,7 @@
<!-- Need Win32 API on .NET Core to ping registry to determine long path support -->
<PackageReference Include="Microsoft.Win32.Registry" />


<Content Include="$(NuGetPackageRoot)microsoft.netcore.compilers\$(MicrosoftNetCoreCompilersVersion)\tools\**\*" CopyToOutputDirectory="PreserveNewest" LinkBase="Roslyn" />
</ItemGroup>

Expand Down
7 changes: 7 additions & 0 deletions src/Tasks/WriteCodeFragment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,23 @@ private string GenerateCode(out string extension)
{
provider = CodeDomProvider.CreateProvider(Language);
}
#if FEATURE_WINFORMS_RESX
Copy link
Contributor

Choose a reason for hiding this comment

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

(This is where it's still #if'ed out that I referenced in earlier comment)

catch (System.Configuration.ConfigurationException ex)
{
Log.LogErrorWithCodeFromResources("WriteCodeFragment.CouldNotCreateProvider", Language, ex.Message);
return null;
}
#endif
catch (SecurityException ex)
{
Log.LogErrorWithCodeFromResources("WriteCodeFragment.CouldNotCreateProvider", Language, ex.Message);
return null;
}
catch (SystemException ex)
{
Log.LogErrorWithCodeFromResources("WriteCodeFragment.CouldNotCreateProvider", Language, ex.Message);
return null;
}

extension = provider.FileExtension;

Expand Down
Loading