dotnet / dotnet/msbuild

TargetFrameworks causes error when a space is in referenced project's path

Open
#8,165 4 comments 0 reactions 0 assignees View on GitHub
bug triaged
Dominant language
C#
Stars
5.5k
Forks
1.5k
Avg merge
1d 8h
Merged PRs (30d)
141

Description

### Issue Description
Simply changing the tag `TargetFramework` to `TargetFrameworks` can cause msbuild to fail to build with the error message:

> error NETSDK1005: Assets file 'project\obj\project.assets.json' doesn't have a target for 'net6.0-windows'. Ensure that restore has run and that you have included 'net6.0-windows' in the TargetFrameworks for your project.

This happens solely because of a space in path of a referenced project, and only when `TargetFrameworks` are used (even with only one moniker).

### Steps to Reproduce
Either see the attached full sample[^1] with log[^2] or follow the steps in an empty dir:

1. `dotnet new classlib -o net6_win`
2. `dotnet new classlib -o "net6 spaced"`
3. `dotnet add net6_win reference "net6 spaced"`
4. change `TargetFramework` to `net6.0-windows` in `net6_win\net6_win.csproj`
5. change `TargetFramework` to `TargetFrameworks` in `net6_win\net6_win.csproj` //this causes the bug
6. `msbuild /restore net6_win`

### Expected Behavior
The projects build when the old `TargetFramework` tag is used, they should build with the new `TargetFrameworks` too.

### Actual Behavior
The build fails only when there is a space on the path and when the new `TargetFrameworks` tag is used.

### Analysis

Removing the space in the name of `net6 spaced.csproj` and in the project reference works around the bug.

### Versions & Configurations
MSBuild version 17.4.0+18d5aef85 for .NET Framework
17.4.0.51802
happens with both net6.0 and net7.0

### Attachments
[^1]:[msbuild_test.zip](https://github.com/dotnet/msbuild/files/10010768/msbuild_test.zip)
[^2]:[msbuild.log](https://github.com/dotnet/msbuild/files/10010786/msbuild.log)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.