-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Setting BaseIntermediateOutputPath breaks netstandard2.0 builds #1518
Comments
This doesn't break the build with a |
It is generally unsafe to set There are two workarounds at the moment:
<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
<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> |
If that Directory.Build.props indeed works at the solution level, that is a fairly clean workaround. Option 2 would also be OK, but seems more fragile (are future SDKs guaranteed to only need Sdk.props and Sdk.targets?). Is there (usable) documentation on which variables MSBuild/CoreSDK/... use, and which one(s) are safe to set when? And which optional props/targets/tasks files are loaded (and when/whence)? |
As @dasMulli mentioned, due to the places that we set the restore directory for NuGet.props/targets/assets, setting $(BaseIntermediateOutputPath) inside body of project should have never "properly" worked/respected in 1.1 - are you sure this worked? We really need a topic on this in the docs. @rainersigwald do know how/where I would file this? Do I just file in the docs repo? |
@davkean we can either add it to https://docs.microsoft.com/en-us/visualstudio/msbuild/common-msbuild-project-properties or start a new page on docs. Usually easiest to file a bug on MSBuild since that's where those of us who could write the initial draft of the doc hang out, but a bug on docs should eventually percolate to us, too. At the moment, we're without a doc writer so it might be a bit. |
Well, I needed APIs that weren't in netstandard1.6, so while I had switched to the new project format (for the multitargeting and built-in nuget pack), I was targeting the desktop framework only (net20/35/40/45). That worked just fine (it still created those restore files, but I suppose they don't actually get used unless target core/std). Workaround 1 does for me, so I'm good. One thing I will say: docs on ALL properties for the various languages would be nice; I was recently bitten by the fact that I set an Instrument property, which apparently triggered the use of a (pretty much undocumented) C# compiler option. Would it not make sense to add namespaces, or at least use consistent prefixes? I would have been far less likely to set CscInstrument or Csc:Instrument. That could even serve as a basic form of documentation - e.g. any property starting with "Sdk:" is explicitly for internal sdk use only. |
@Zastai Thanks for the feedback and ideas, agreed our documentation story/IntelliSense docs aren't great. It's something that I think about a lot, and have some other ideas to make it better (for example, by stop showing irrelevant stuff). |
There's also dotnet/docs#2642 |
We have #803 to detect the case of BaseIntermediatePath set too late and trigger an error or warning. We absolutely do need better documentation on this. I've added an explicit comment about it to dotnet/docs#2642. I'm closing this since the action items (docs + diagnostics) are tracked elsewhere. |
I couldn't make option 2 work in @dasMulli's post for a Xamarin.Forms project on Visual Studio for Mac, for option 1 the configuration setting (Debug/Release) is not available. Does anyone know of a way to get the configuration setting from Directory.Build.props? Thanks. |
@rraallvv the <PropertyGroup>
<Configuration Condition="'$(Configuration)' == ''">Debug</Configuration>
<BaseIntermediateOutputPath>$(MSBuildThisFileDirectory)obj\$(Configuration)\$(MSBuildProjectName)\</BaseIntermediateOutputPath>
</PropertyGroup> This default would be performed by the time |
@dasMulli thanks a lot. |
@nguerrera, @dasMulli, please reopen this issue! |
Because:When I use a
Steps to reproduce:
What the hell we make it wrong? |
@DoCode Please file a new bug. |
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
dotnet new classlib
obj
folder<BaseIntermediateOutputPath>foo\</BaseIntermediateOutputPath>
(any value works as long as it's not
obj\
)dotnet restore
this correctly creates the relevant files in
foo\
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
andExternalException
) 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 providesExternalException
, 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).
The text was updated successfully, but these errors were encountered: