question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Setting BaseIntermediateOutputPath breaks netstandard2.0 builds

See original GitHub issue

Setting 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

  1. run: dotnet new classlib
  2. delete the obj folder
  3. edit project file, adding <BaseIntermediateOutputPath>foo\</BaseIntermediateOutputPath> (any value works as long as it’s not obj\)
  4. run: dotnet restore this correctly creates the relevant files in foo\
  5. 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:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:16 (8 by maintainers)

github_iconTop GitHub Comments

14reactions
dasMullicommented, Aug 24, 2017

It is generally unsafe to set BaseIntermediateOutputPath in the “main body” of a project.

There are two workarounds at the moment:

  1. Create a Directory.Build.props file at project or solution level that define the variable:
<Project>
  <PropertyGroup>
    <BaseIntermediateOutputPath>$(MSBuildThisFileDirectory)obj\$(MSBuildProjectName)\</BaseIntermediateOutputPath>
  </PropertyGroup>
</Project>

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 uses BaseIntermediateOutputPath).

  1. Move from the <Project Sdk=".."> syntax to explicitly importing the Sdk’s props and targets file and set the property early in the project file:
<Project>
  <PropertyGroup>
    <BaseIntermediateOutputPath>some\other\dir\</BaseIntermediateOutputPath>
  </PropertyGroup>
  <Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" />

  <!-- All your project's other content here -->

  <Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />
</Project>
2reactions
hartmannr76commented, Aug 24, 2017

The More You Know

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Visual Studio Developer Community
With the fix, the NuGet restore output will still go in the obj/ file under the project folder, but the project should build...
Read more >
MSBuild reference for .NET SDK projects
The PreserveCompilationContext property allows a built or published application to compile more code at run time using the same settings that ...
Read more >
MSBuild and BaseIntermediateOutputPath Variable
Hello,. I use FinalBuilder to build several .NET assemblies; the same project compiled against different .NET frameworks.
Read more >
c# - .netstandard 2.0 project Always compiles to AnyCPU
Our first test is to modify one interface to .NetStandard2.0. This should work since the interface has 0 dependencies. Note: Due to some...
Read more >
Please stop lying about .NET Standard 2.0 support!
In this post I have a bit of a rant about Microsoft's NuGet packages lying about supporting .NET Standard 2.0 when they kinda...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found