NuGet package build logic ignored under some obj customizations
- Dominant language
- C#
- Stars
- 5.5k
- Forks
- 1.5k
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 133
Description
If you're in a situation where you want to customize the obj directory (`IntermediateOutputPath`) path, you may run into a situation where the build ignores packages' .props and .targets files.
This happens if you assign a value to `IntermediateOutputPath` _after_ importing `Microsoft.Common.props`, which is easy to do, especially with Sdk imports.
```csproj
SomeCustomValue
```
The reason this causes silent errors is that NuGet restore happens at the solution level. Restore asks each project for some information, and gets the _final_ value of the obj directory, after the top-to-bottom evaluation of the project, so it gets the customized value. NuGet then generates .props and .targets files in that location.
When the actual build begins, `Microsoft.Common.props` attempts to import the generated file from the _default_ obj location, because at the time of the import, the property hasn't been set to its custom value. No file is present in that location and the build silently continues, with no NuGet-package-delivered customizations.
## Workaround
Customize the obj directory using [`Directory.Build.props`](https://docs.microsoft.com/en-us/visualstudio/msbuild/customize-your-build), or another mechanism that sets `BaseIntermediateOutputPath` _before_ the `MSBuildProjectExtensionsPath` in `Microsoft.Common.props`.
📝 Note: doing this means that you do not have access to very many properties that are set to defaults in the imported props. Be careful to use only built-in properties or constants, and not rely on things like `$(AssemblyName)`.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.