CommonBuildToolset / CBT.Modules

Modules for CBT
MIT License
9 stars 5 forks source link

CBT.UnifiedOutputDir breaks build for non-.NET Core projects when added #253

Open Porges opened 6 years ago

Porges commented 6 years ago

I took the sample (internal) project "Template-VS2017-CloudBuild" which worked fine, and added CBT.UnifiedOutputDir (2.0.16) to it. This causes the following error to happen:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\NuGet\15.0\Microsoft.NuGet.targets(186,5):
error : Your project is not referencing the ".NETFramework,Version=v4.6" framework.
Add a reference to ".NETFramework,Version=v4.6" in the "frameworks" section of your project.json, and then re-run NuGet restore.

I also created a new .NET Core project which was not affected by this problem.

Porges commented 6 years ago

There's another problem in that the project.assets.json is being put in the root of the shared intermediate output folder (obj)... which obviously causes issues when all projects are sharing it 🙂

Error message is like:

1>C:\Program Files\dotnet\sdk\2.1.300\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(198,5): error : Assets file '...\obj\project.assets.json' doesn't have a target for '.NETStandard,Version=v2.0'. Ensure that restore has run and that you have included 'netstandard2.0' in the TargetFrameworks for your project.
jeffkl commented 6 years ago

Thanks for reporting this. The CBT.UnifiedOutputDir appears to have a conflict with the fundamental concept of what BaseIntermediateOutputPath is. In NuGet 3.0, they took over BaseIntermediateOutputPath and treated it as a unique-per-project but platform and configuration agnostic folder. However, CBT.UnifiedOutputDir treats BaseIntermediateOutputPath as a repository-wide folder where projects then add on to it.

So the root of the issue is that the project.assets.json file for all projects in the tree are written to the same location. This means that during build, projects are using another project's assets file which is wrong and the build fails.

So we'll need to rework the package if we ever want it to work with PackageReference and NuGet v3+

Porges commented 6 years ago

I ended up just doing the following in Directory.Build.props:

<PropertyGroup>
  <OutputPath>$(EnlistmentRoot)\bin\$(Configuration)\$(Platform)\$(MSBuildProjectName)</OutputPath>
  <OutDir>$(OutputPath)\$(TargetFramework)</OutDir>
</PropertyGroup>

Not sure how correct that is but it produces the desired results for me.

Sharing intermediate output directories is not something I need to have a unified output directory 🙂