dotnet / dotnet/msbuild

PS D:\code\CX\src\Smp\ConsoleApp1> dotnet run C:\Program Files\dotnet\sdk\10.0.203\NuGet.targets(679,5): error MSB4044: 未给任务“GetRestoreProjectStyleTask”的必需参数“MSBuildProjectName”赋值。 生成失败。请修复生成错误并重新运行。 PS D:\code\CX\src\Smp\ConsoleApp1>

Open
#13,674 0 comments 0 reactions 0 assignees View on GitHub
backlog gathering-feedback triaged
Dominant language
C#
Stars
5.5k
Forks
1.5k
Avg merge
1d 8h
Merged PRs (30d)
141

Description

### Issue Description

When a .NET project file is named without a root filename — for example, `.csproj` instead of `MyApp.csproj` — MSBuild fails with the following error:

```
error MSB4044: The "GetRestoreProjectStyleTask" task was not given a value for the required parameter "MSBuildProjectName".
```

This error message does not point to the actual cause (invalid project file name) and makes debugging difficult.

### Steps to Reproduce

This issue was discovered when a project file was accidentally renamed to `.csproj`. The resulting error message gave no indication that the file name itself was the problem. A validation step during project file parsing would significantly improve developer experience.

### Expected Behavior

MSBuild should detect during project evaluation that the project file name is invalid (missing root name) and produce a clear, actionable error message such as:

```
error MSBxxxx: The project file name '.csproj' is invalid. A project file must have a root file name (e.g., 'MyApp.csproj').
```

### Actual Behavior

MSBuild throws `MSB4044` about a missing `MSBuildProjectName` parameter, which obscures the root cause.

### Analysis

MSBuild throws `MSB4044` about a missing `MSBuildProjectName` parameter, which obscures the root cause.

## Steps to Reproduce

1. Create a new console project:
```
dotnet new console -n TestApp
```
2. Rename the project file to only an extension:
```
Rename-Item TestApp.csproj .csproj
```
3. Attempt to build or run:
```
dotnet build
```
4. Observe the `MSB4044` error.

### Versions & Configurations

PS D:\code\CX\src\Smp\ConsoleApp1> dotnet --info
.NET SDK:
Version: 10.0.203
Commit: c23858a6d8
Workload version: 10.0.200-manifests.ef86bccd
MSBuild version: 18.3.3+c23858a6d

运行时环境:
OS Name: Windows
OS Version: 10.0.19045
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\10.0.203\

已安装 .NET 工作负载:
没有要显示的已安装工作负载。
已配置为在安装新清单时使用 workload sets。
未安装任何 workload sets。运行 “dotnet workload restore” 以安装工作负载集。

Host:
Version: 10.0.7
Architecture: x64
Commit: b16286c228

.NET SDKs installed:
10.0.203 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 10.0.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 10.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 10.0.7 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
None

Environment variables:
Not set

global.json file:
Not found

Learn more:
https://aka.ms/dotnet/info

Download .NET:
https://aka.ms/dotnet/download
PS D:\code\CX\src\Smp\ConsoleApp1>

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.