Skip to content
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

Can not build the build target of a specific project within a solution #5722

Open
goyzhang opened this issue Sep 8, 2020 · 12 comments
Open
Labels
Area: Solution (.sln) Issues related to parsing .sln files or building solutions bug triaged
Milestone

Comments

@goyzhang
Copy link

goyzhang commented Sep 8, 2020

Issue Description

I'm following the guide from https://docs.microsoft.com/en-us/visualstudio/msbuild/how-to-build-specific-targets-in-solutions-by-using-msbuild-exe
Some targets cannot be run from the solution level using msbuid .sln -t::

Reproduce

For example,msbuild Consoleapp.sln -t:ConsoleApp:build gives me

error MSB4057: The target "ConsoleApp:build" does not exist in the project.

However, rebuild and clean seems to be working.

Analysis

I've checked .sln.metaproj. There are only ConsoleApp.Clean, Console:Public and Console:Rebuild created. No build or custom target.

Versions & Configurations

Microsoft (R) Build Engine version 16.7.0+b89cb5fde for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

16.7.0.37604

@goyzhang goyzhang added bug needs-triage Have yet to determine what bucket this goes in. labels Sep 8, 2020
@benvillalobos
Copy link
Member

benvillalobos commented Sep 9, 2020

Team Triage: Can you share a small solution that reproduces this behavior? Given the target names that you're sharing, it sounds like the project name may not be what you think it is.

@goyzhang
Copy link
Author

@benvillalobos Yes, check this https://github.com/goyzhang/SampleConsoleApp
Running SampleConsoleApp>msbuild -t:ConsoleApp:build gives you the error.
I think MSBuild should raise custom targets from .csproj into .sln.metproj. Or am I wrong?

@benvillalobos
Copy link
Member

Team Triage: You can build the default target in a project (which is usually build) by specifying just the project name with nothing after the colon. However, it does appear to be a bug that you can't specify the build target by name.

@benvillalobos benvillalobos changed the title MSB4057 when build a specific target of a specific project in a solution Can not build the build target of a specific project within a solution Sep 16, 2020
@benvillalobos benvillalobos added Area: Solution (.sln) Issues related to parsing .sln files or building solutions and removed needs-triage Have yet to determine what bucket this goes in. labels Sep 16, 2020
@benvillalobos benvillalobos added this to the Backlog milestone Sep 16, 2020
@goyzhang
Copy link
Author

Actually I got the answer from docs and this topic: https://stackoverflow.com/a/49311810/6223314
Where it should work not only for built-in targets but also for custom targets. However, now only rebuild and clean are in .sln.metaproj

@bematteo
Copy link

Since updating Visual Studio to 16.10 I started having the same problem.
rebuild and clean targets work fine, but the build target fails.

@jespergustinmsft
Copy link

I just noticed the same thing in VS16.10.

I'm trying to build a project name in a solution folder using: -t:FolderName\ProjectName
But this fails. However: -t:FolderName\ProjectName:Rebuild
works fine

@kikijiki
Copy link

kikijiki commented Jun 1, 2021

Same issue here, all my builds are failing now.

@benvillalobos Could this be taken out of the backlog?

@VonOgre
Copy link

VonOgre commented Jun 1, 2021

Running into the same issue as jespergustinmsft, where specifying what should be a legitimate target in the metaproj to build a particular csproj no longer works with MSBuild after updating to VS16.10. However the :Clean and :Rebuild flavored targets still function.

when specifying: MSBuild mysolution.sln -t:FolderName\ProjectName
it seems to iterate through all of the projects and tries to execute the "FolderName\ProjectName" target in each one, rather than executing that target from the .sln.metaproj

@rainersigwald
Copy link
Member

Problems with specifying a project name in a solution in 16.10 are likely #6373, which will be fixed with Visual Studio 16.10.1.

@bematteo
Copy link

Confirmed that 16.10.1 works fine here.

@goyzhang
Copy link
Author

@benvillalobos Yes, check this https://github.com/goyzhang/SampleConsoleApp
Running SampleConsoleApp>msbuild -t:ConsoleApp:build gives you the error.
I think MSBuild should raise custom targets from .csproj into .sln.metproj. Or am I wrong?

I'm still getting the error in 16.10.2+857e5a733

@bematteo
Copy link

I think in my case the problem was fixed because I don't put the :build explicitly.

I checked on 16.10.2 that with @goyzhang sample, msbuild -t:ConsoleApp works but msbuild -t:ConsoleApp:build does not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Solution (.sln) Issues related to parsing .sln files or building solutions bug triaged
Projects
None yet
Development

No branches or pull requests

8 participants