2

The solution I am working on includes a net452 project which has two text files which are set to:

Build Action: Content
Copy to Output Directory: Do not copy

These files are accessed in the code as follows:

_listItems = Properties.Resources.ListItems.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);

When the solution is built within Visual Studio 2017 the resources are loaded as expected.

When the solution is built from the command line using msbuild (Build Engine version 15.3.409.57025) the resources are loaded as expected.

However when building the solution from the command line using dotnet build or dotnet msbuild the resources are not loaded correctly, instead the string type replaces the file content:

System.String, mscorlib, Version=4.0.0.0, Culture=neutral...

Looking at the output msbuild is targeting .NET framework:

Microsoft (R) Build Engine version 15.3.409.57025 for .NET Framework

where as dotnet msbuild is targeting .Net Core

Microsoft (R) Build Engine version 15.3.409.57025 for .NET Core

What is the reason for this different behaviour, and is it possible to get the resources to be included correctly using dotnet build?

TonE
  • 2,823
  • 5
  • 25
  • 47

2 Answers2

2

The .NET Core version of MSBuild that is distributed with the dotnet based tooling (".NET Core SDK" or ".NET CLI") does not support strongly typed resources or file references. Only key-value string pairs are supported. It does not matter what framework is targeted, but which tooling is used to build.

This is because the serialisation of resources using file references or strongly typed resources uses types from System.Windows.Forms which aren't available on .NET Core.

See this GitHub issue for reference.

If you need embedded files or strongly typed resources, you have to use the full-framework MSBuild distributed with Visual Studio or Mono.

Martin Ullrich
  • 78,211
  • 20
  • 211
  • 189
  • Thanks, this was exactly the answer I was looking for. – TonE Jan 19 '18 at 08:35
  • Despite using the full .Net version of Msbuild we are seeing the same problem on our CI server after it performs a web application publish using dotnet publish. Is this to be expected? – TonE Jan 22 '18 at 16:03
  • 1
    Yes, you’ll need to change to `msbuild /t:Publish /p:Configuration=Release` – Martin Ullrich Jan 22 '18 at 16:11
0

Well, dotnet build is the .Net Core command line build tool and msbuild is running on standard .Net Framework. A more detailed comparison http://www.natemcmaster.com/blog/2017/07/05/msbuild-task-in-nuget/

Are you targeting .Net or .Net Core Framework?

Niko
  • 418
  • 3
  • 9
  • All the projects in the solution have net452 as their target framework – TonE Jan 18 '18 at 19:39
  • Also this post suggests either should be OK: https://stackoverflow.com/questions/43422488/relationship-between-the-dotnet-cli-and-the-new-vs2017-msbuild – TonE Jan 18 '18 at 19:51