Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ Copyright (c) .NET Foundation. All rights reserved.
('$(TargetFrameworkIdentifier)' == '.NETCoreApp' and '$(_TargetFrameworkVersionWithoutV)' >= '3.0')">true</GenerateResourceUsePreserializedResources>
</PropertyGroup>

<PropertyGroup>
<EmbeddedResourceUseDependentUponConvention
Condition="'$(EmbeddedResourceUseDependentUponConvention)' == '' and
(('$(TargetFrameworkIdentifier)' == '.NETCoreApp' and '$(_TargetFrameworkVersionWithoutV)' >= '3.0') or
('$(TargetFrameworkIdentifier)' == '.NETStandard' and '$(_TargetFrameworkVersionWithoutV)' >= '2.1'))">true</EmbeddedResourceUseDependentUponConvention>
</PropertyGroup>

<PropertyGroup>
<CoreBuildDependsOn>
_CheckForBuildWithNoBuild;
Expand Down
84 changes: 84 additions & 0 deletions src/Tests/Microsoft.NET.Build.Tests/GenerateResourceTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using Microsoft.NET.TestFramework;
using Microsoft.NET.TestFramework.Assertions;
using Microsoft.NET.TestFramework.Commands;
using Microsoft.NET.TestFramework.ProjectConstruction;
using Xunit;
using Xunit.Abstractions;

namespace Microsoft.NET.Build.Tests
{
public class GenerateResourceTests : SdkTest
{

public GenerateResourceTests(ITestOutputHelper log) : base(log)
{
}

[Theory(Skip="https://github.com/microsoft/msbuild/issues/4488")]
[InlineData("netcoreapp3.0", true)]
public void DependentUponTest(string targetFramework, bool isExe)
{
var testProject = new TestProject
{
Name = "HelloWorld",
IsSdkProject = true,
TargetFrameworks = targetFramework,
IsExe = isExe,
SourceFiles =
{
["Program.cs"] = @"
using System;

namespace SomeNamespace
{
public static class SomeClass
{
public static void Main(string[] args)
{
var resourceManager = new global::System.Resources.ResourceManager(""SomeNamespace.SomeClass"", typeof(SomeClass).Assembly);
Console.WriteLine(resourceManager.GetString(""SomeString""));
}
}
}
",
},
EmbeddedResources =
{
["Program.resx"] = @"
<root>
<data name=""SomeString"" xml:space=""preserve"">
<value>Hello world from a resource!</value>
</data>
</root>
",
}
};

var testAsset = _testAssetsManager
.CreateTestProject(testProject, identifier: targetFramework + isExe)
.Restore(Log, testProject.Name);

var buildCommand = new BuildCommand(
Log,
Path.Combine(testAsset.TestRoot, testProject.Name));

buildCommand
.Execute()
.Should()
.Pass();

var outputDirectory = buildCommand.GetOutputDirectory(targetFramework);

var runCommand = new RunExeCommand(Log, Path.Combine(outputDirectory.FullName, "HelloWorld.exe"));
runCommand
.Execute()
.Should()
.Pass()
.And.HaveStdOutContaining("Hello world from a resource!");
}
}
}