Setting BaseIntermediateOutputPath breaks netstandard2.0 builds
See original GitHub issueSetting BaseIntermediateOutputPath breaks netstandard2.0 builds
I have a solution with multiple projects. These import a common properties file (as the first thing in the project file), which set BaseIntermediateOutputPath (along with IntermediateOutputPath and OutputPath) in order to have build artifacts outside the source tree. This has so far worked fine.
However, with the 2.0 SDK, this breaks when targeting netstandard2.0; none of the types from the standard libraries are found. As such, this seems related to #803; however, the same problem does not occur when targeting netcoreapp2.0 (which I would assume to have the same basic setup).
Steps to Reproduce
- run:
dotnet new classlib
- delete the
obj
folder - edit project file, adding
<BaseIntermediateOutputPath>foo\</BaseIntermediateOutputPath>
(any value works as long as it’s notobj\
) - run:
dotnet restore
this correctly creates the relevant files infoo\
- run:
dotnet build
lots of CS0518 and CS0246 errors ensue
Partial Workaround
To a certain extent this can be worked around by explicitly adding PackageReference entries for the needed standard library assemblies (e.g. adding System.Runtime 4.3.0 makes the basic classlib sample compile). Note that adding a reference to NETStandard.Library 2.0.0 does not help; that results in a build warning plus the same compilation issues).
However, for some new APIs (e.g. SerializableAttribute
and ExternalException
) it does not seem so obvious to find which packages to reference (the API docs list assemblies, not packages; neither System.Runtime nor System.Runtime.InteropServices provides ExternalException
, despite what the docs suggest).
Note that without #1486 I could probably just customize RestoreOutputPath instead (unless there are other files that are created via BaseIOP instead of IOP/ROP/OP).
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:16 (8 by maintainers)
Top GitHub Comments
It is generally unsafe to set
BaseIntermediateOutputPath
in the “main body” of a project.There are two workarounds at the moment:
Directory.Build.props
file at project or solution level that define the variable:This file will be automatically imported by all projects in the directory tree early enough to set the property (= imported in the
Microsoft.Common.props
file before it usesBaseIntermediateOutputPath
).<Project Sdk="..">
syntax to explicitly importing the Sdk’s props and targets file and set the property early in the project file:Option 2 worked great!
I’m going to try option 1 out later because that seems like it could be shared better across a solutions projects.