dotnet / dotnet/msbuild

Multitarget Issues: Msbuild doesn't work. Visual Studio Build works but shouldn't.

Open
#2,763 0 comments 2 reactions 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

I created a multitarget library in VS 2017 using the SDK style csproj. It include netstandard16, net35, portability profile24 (net45 and sl5). I used DefineConstants to make a flag to turn off some of the properties in the AssemblyInfo.file in the portability target

Everything was building in VS, but I could not get it to build with msbuild from the command line \ TeamCity.
The error was:
```
C:\Program Files\dotnet\sdk\2.0.3\Sdks\Microsoft.NET.Sdk\Sdk\Sdk.targets(41,3): error MSB4019: The imported project "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\Microsoft\Portable\v4.0\Microsoft.Portable.CSharp.targets" was not found. Confirm that the path in the declaration is correct, and that the file exists on disk
```

I worked around this buy running the build out of the Visual Studio MsBuild directory. This didn't work in TeamCity and I had to use the work around of copying the Portable\ directory from Professional\ to BuildTools\ directory.
After the build passed this step. I had a few more errors

```
Properties\AssemblyInfo.cs(24,12): error CS0246: The type or namespace name 'GuidAttribute' could not be found (are you missing a using directive or an assembly reference?)
Properties\AssemblyInfo.cs(24,12): error CS0246: The type or namespace name 'GuidAttribute' could not be found (are you missing a using directive or an assembly reference?)
```

This was easy but strange. It was failing at the .NET Core build (it is a little unclear what target is running, a small log message would help before each type of target). I didn't include a package reference. The weird part is that Visual Studio successfully built this project and Intellesense looked good! If it had failed in VS I would have caught it earlier.

Relevant Project file Parts
```xml
net35;netstandard2.0;portable-net45+sl5



$(DefineConstants);FEATURE_TOGGLE_NOTPORTABLE







```

```
#if FEATURE_TOGGLE_NOTPORTABLE
[assembly: Guid("--Real Guid--")]
#endif
```

Command line
```
msbuild myProject.sln
```

### Expected behavior
Build on msbuild from any path exactly like it does in VS.
VS should fail to build if a dependency is missing.

### Actual behavior
msbuild only works from the Visual Studio path
VS actually builds the project without the required reference.

### Environment data
`msbuild /version` output:
Microsoft (R) Build Engine version 15.4.8.50001 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

15.4.8.50001

OS info:
Windows Server 2012 R2

If applicable, version of the tool that invokes MSBuild (Visual Studio, dotnet CLI, etc):
Visual Studio 2017 15.3 -> 15.4.5 (I upgraded to see if that was the issue)

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reproducing `msbuild myProject.sln` from the BuildTools and Visual Studio MSBuild directories, focusing on the missing Microsoft.Portable.CSharp.targets import. Then compare the multitarget project file and Properties/AssemblyInfo.cs behavior for the GuidAttribute error. Done means command-line builds work from any path and Visual Studio fails when a required reference is missing.

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
Needs clarification
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.