Skip to content

dotnet-clean and project.assets.json in 2.0 #8740

Closed
@sstevenkang

Description

@sstevenkang

I would like to know why "dotnet clean" depends on project.assets.json file. This new behavior in 2.0 is something we can work around, but I would like to understand why this change in behavior was introduced and what is the project structure expectation of dotnet cli.

Is multiple .csproj files in a single directory not supported/encouraged?

Steps to reproduce

In our project, we have this folder structure for historical reasons:

/obj
/bin
/src
Project.Net35.csproj
Project.Net45.csproj

Pre 2.0, we used to do following commands in sequence:

# build net35
dotnet clean Project.Net35.csproj
dotnet restore Project.Net35.csproj
dotnet build Project.Net35.csproj

# build net45
dotnet clean Project.Net45.csproj
dotnet restore Project.Net45.csproj
dotnet build Project.Net45.csproj

Both .csproj are in the new vs2017 csproj format that starts with <Project Sdk="Microsoft.NET.Sdk">

Expected behavior

The above folder structure worked pre-2.0 because "dotnet clean" command did not take a dependency/make a reference to project.assets.json file and succeeded.

Actual behavior

With 2.0, we see the following error message during dotnet clean:

C:\Program Files\dotnet\sdk\2.0.0\Sdks\Microsoft.NET.Sdk\build\Microsoft.PackageDependencyResolution.targets(165,5): error : Assets file 'd:\workspace\Project\obj\project.assets.json' doesn't have a target for '.NETFramework,Version=v4.5'. Ensure that restore has run and that
you have included 'net45' in the TargetFrameworks for your project. [d:\workspace\Project\Project.Net45.csproj] [
d:\workspace\build.proj]

I think we can workaround this by specifying different obj directory per project or doing dotnet restore -f before dotnet clean. Ideally, we would build for both frameworks in a single .csproj, but it's not something we can invest time in currently.

Environment data

dotnet --info output:

.NET Command Line Tools (2.0.0)

Product Information:
 Version:            2.0.0
 Commit SHA-1 hash:  cdcd1928c9

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.14393
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\2.0.0\

Microsoft .NET Core Shared Framework Host

  Version  : 2.0.0
  Build    : e8b8861ac7faf042c87a5c2f9f2d04c98b69f28d

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions