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.

"Dotnet build" command should generate an error directing you to use "dotnet msbuild" if you try to specify a target to run (/t:TargetName)

See original GitHub issue

Once you get used to using dotnet build to build your MSBuild projects, and you learn that you can pass MSBuild command-line parameters, it’s natural to try something like this:

dotnet build MyProj.csproj /t:MyCustomTarget

That’s what I did and then I spent like an hour banging my head against the wall trying to figure out why it was trying to build the “Build” target when “MyCustomTarget” didn’t have any dependencies on it. The CLI was passing both /t:Build and /t:MyCustomTarget to MSBuild.

Now I know that I should use dotnet msbuild instead of dotnet build for this. But why the difference? I think it will be pretty common for people who want to run custom targets to not know there is a separate msbuild command, and to run into this same issue.

I would propose that the dotnet build command should do what the dotnet msbuild command does today, which is to specify no specific targets. Then the default target will be built, which will be “Build” on normal projects. Then there won’t be any need for a separate dotnet msbuild command.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:15 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
dasMullicommented, Jan 26, 2017

Related: CoreRT asks you to run dotnet build /t:LinkNative so that their additional target runs after build. Seems legit now but since a decision on how build should work will require target authors to follow, it should be decided soon to avoid breaking changes that require documentation or target changes.

1reaction
mellinoecommented, Jan 26, 2017

Personally, I find it pretty odd that running dotnet build on my project doesn’t run the default targets that I’ve specified. Additionally, the difference between dotnet build and dotnet msbuild seems artificial to me, and not very helpful. I feel like having dotnet build be an alias for dotnet msbuild /t:build is only going to help people make mistakes, not avoid them. If a project specifies non-standard default targets, then why would I want dotnet build to run a potentially nonexistant “Build” target? Just trying to understand, maybe there’s something I’m missing.

Read more comments on GitHub >

github_iconTop Results From Across the Web

dotnet msbuild command - .NET CLI
When you don't want to build the project and you have a specific target you want to run, use dotnet build or dotnet...
Read more >
MSBuild Target not running in NET Core Project
Once the Pack target is finished, i can push to my local NuGet server. Make sure you have the checkbox unchecked on the...
Read more >
.NET | TeamCity On-Premises Documentation
NET command, and TeamCity will run it as is. ... If you have a finished build, you can use the file/directory selector here....
Read more >
Automate your .NET project builds with NUKE a cross- ...
The execution model is using Target which can relate one another and create a directed dependency graph. In the generated code we can...
Read more >
10 commands you don't want to be without in .Net Core
Here's a full list of commands that runs restore implicitly: dotnet new; dotnet build; dotnet build-server; dotnet run; dotnet test; dotnet publish; dotnet...
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