`dotnet publish --no-build` fails in a repo using Microsoft.Build.Traversal
Closed this issue · 5 comments
Also seems to happen with dotnet pack
.
Thanks I'll try and look at this today and see if I can figure out the problem!
@alexrp this celerity repo is using a Vezel.Zig.Sdk, which has highly customized the .NET SDK and I believe is leading to the problem. I cannot repro with a simple setup:
dirs.proj
<Project Sdk="Microsoft.Build.Traversal/3.4.0">
<ItemGroup>
<ProjectReference Include="ProjectA\ProjectA.csproj" />
<ProjectReference Include="ProjectB\ProjectB.csproj" />
</ItemGroup>
</Project>
The dotnet build --no-restore
and dotnet build --no-restore --no-build
command respect the targest to run:
D:\repros\traversal-no-build>dotnet restore
Determining projects to restore...
All projects are up-to-date for restore.
D:\repros\traversal-no-build>dotnet build --no-restore
MSBuild version 17.5.0+6f08c67f3 for .NET
ProjectB -> D:\repros\traversal-no-build\ProjectB\bin\Debug\net6.0\ProjectB.dll
ProjectA -> D:\repros\traversal-no-build\ProjectA\bin\Debug\net6.0\ProjectA.dll
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:00.73
D:\repros\traversal-no-build>dotnet publish --no-restore --no-build
MSBuild version 17.5.0+6f08c67f3 for .NET
ProjectB -> D:\repros\traversal-no-build\ProjectB\bin\Debug\net6.0\publish\
ProjectA -> D:\repros\traversal-no-build\ProjectA\bin\Debug\net6.0\publish\
Do you have a repro with a set of projects that only use the .NET SDK?
Thanks for taking a look; that's interesting. The errors popped up in projects completely unrelated to the src/runtime/native
project that's using my Zig SDK (e.g. src/generators
), so it didn't even occur to me that the issue could be there. 🤔
C:\program files\dotnet\sdk\8.0.100-preview.2.23157.25\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(161,5): error NETSDK1085: The 'NoBuild' property was set to true but the 'Build' target was invoked. [C:\Users\alex\source\repos\vezel\celerity\src\generators\generators.csproj]
I tried removing all references to the native project, and sure enough, it now works. What's curious is that dotnet build && dotnet publish --no-build
in e.g. src/runtime/core
(which references src/runtime/native
) works fine. It only seems to break if done from the repo root (where celerity.proj
using Microsoft.Build.Traversal sits).
I would assume that the fault lies with my SDK somehow. Do you happen to know if Traversal has some special requirements for how the Publish
target is set up that the regular .NET SDK does not?
I'm not 100% sure, the Traversal SDK is essentially just dispatching the Publish target to each project, similar to what a solution file would do.
https://github.com/microsoft/MSBuildSdks/blob/main/src/Traversal/Sdk/Sdk.targets#L234
The only fancy logic is that if you specify --no-build
, the .NET CLI passes a global property, NoBuild=true
which Traversal respects by not making Publish depend on Build.
https://github.com/microsoft/MSBuildSdks/blob/main/src/Traversal/Sdk/Sdk.targets#L100-L105
For --no-restore
, the NET CLI just doesn't invoke the Restore target first. I would imagine the problem is somewhere in your SDK the NoBuild
property isn't being respected?