dotnet / dotnet/msbuild

Csc task cannot be found when using custom toolset

Open
#3,002 5 comments 1 reaction 0 assignees View on GitHub
triaged
Dominant language
C#
Stars
5.5k
Forks
1.5k
Avg merge
1d 13h
Merged PRs (30d)
133

Description

### Steps to reproduce

Minimal repro located here: https://github.com/dfederm/msbuild/tree/csc-not-found-custom-toolset/src/Samples/CscNotFoundWithCustomToolset

After building, run something like:
```
"D:\msbuild\artifacts\Debug\bin\Samples\CscNotFoundWithCustomToolset\net46\CscNotFoundWithCustomToolset.exe" "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\"
```

### Expected behavior
The Compile target succeeds

### Actual behavior
Output:
```
__________________________________________________
Project "D:\msbuild\src\Samples\CscNotFoundWithCustomToolset\Test.csproj" (Compile target(s)):

C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Roslyn\Microsoft.CSharp.Core.targets(84,5): error MSB4062: The "Microsoft.CodeAnalysis.BuildTasks.Csc" task could not be loaded from the assembly \Microsoft.Build.Tasks.CodeAnalysis.dll. Could not load file or assembly 'file:///D:\Microsoft.Build.Tasks.CodeAnalysis.dll' or one of its dependencies. The system cannot find the file specified. Confirm that the declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask.
Done building project "Test.csproj" -- FAILED.
Compile failed
```

### Environment data
Using the latest version of Microsoft.Build.Runtime (15.5.180.1)

### Other
Talked with @cdmihai and one guess to a solution would be to change Microsoft.Common.tasks from:
```

```

to
```

```

That way it always looks next to Roslyn adjacent to the same place it imported the targets from.

Or actually I wonder why the Roslyn tasks aren't defined as a `` in the Roslyn targets in the first place like any other task. IMHO the Csc task doesn't need to be "special".

Contributor guide

No contributing guide indexed for this repository

Research direction

Build and run the sample in src/Samples/CscNotFoundWithCustomToolset using the command from the issue to reproduce MSB4062. Then inspect Microsoft.Common.tasks and the Roslyn targets around the UsingTask declarations, comparing how the task assembly is resolved. Done means the sample's Compile target succeeds with the custom toolset.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
build-system, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.