dotnet / NuGet.BuildTasks

The build tasks used to pick up package content from project.lock.json.
MIT License
45 stars 61 forks source link

Fix handling of content items #53

Closed tmeschter closed 4 years ago

tmeschter commented 5 years ago

Fixes https://github.com/dotnet/project-system/issues/3042.

Consider the following content files from a sample project.assets.json file:

  "targets": {
    ".NETFramework,Version=v4.7.2": {
      "DryIocZero/4.0.0-preview-04": {
        "type": "package",
        "contentFiles": {
          "contentFiles/cs/any/Container.Generated.tt": {
            "buildAction": "None",
            "codeLanguage": "cs",
            "copyToOutput": false
          },
          "contentFiles/cs/any/Container.cs": {
            "buildAction": "Compile",
            "codeLanguage": "cs",
            "copyToOutput": false
          },
          "contentFiles/cs/any/ImTools.cs": {
            "buildAction": "Compile",
            "codeLanguage": "cs",
            "copyToOutput": false
          },
          "contentFiles/cs/any/Registrations.ttinclude": {
            "buildAction": "None",
            "codeLanguage": "cs",
            "copyToOutput": false
          },
          "contentFiles/any/any/MyAwesomeFile.txt": {
            "buildAction": "None",
            "codeLanguage": "any",
            "copyToOutput": false
          },
          "contentFiles/cs/net472/Alpha.cs": {
            "buildAction": "Compile",
            "codeLanguage": "cs",
            "copyToOutput": false
          },
          "contentFiles/any/net472/AnyNet472.txt": {
            "buildAction": "None",
            "codeLanguage": "any",
            "copyToOutput": false
          }
        },

Currently, in a C# project we'll only create MSBuild items for three of these:

I believe the correct behavior is to create MSBuild items for all seven.

There are two overlapping issues:

  1. We simply ignore any item that specifies "buildAction": "None" on the assumption that these items do not participate in the build (which is a bad assumption, and out-of-sync with what happens in SDK-style projects).
  2. If any item in contentFiles has a codeLanguage matching the project language (e.g. C#, VB, F#, etc.) then we ignore those with "codeLanguage": "any". I believe the correct behavior is to always pick up all the files marked with "codeLanguage": "any", plus all the items with a codeLanguage that matches the project language.
davkean commented 5 years ago

tag @nkolev92

dmonroym commented 4 years ago

We've moved things around this repo. Please reopen this PR against master if you want us to take a look at this again.