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

-targets command-line option doesn't work with solution file #7697

Open
ghogen opened this issue Jun 10, 2022 · 15 comments · Fixed by #8588
Open

-targets command-line option doesn't work with solution file #7697

ghogen opened this issue Jun 10, 2022 · 15 comments · Fixed by #8588
Labels
Area: Solution (.sln) Issues related to parsing .sln files or building solutions bug help wanted Issues that the core team doesn't plan to work on, but would accept a PR for. Comment to claim. triaged
Milestone

Comments

@ghogen
Copy link
Contributor

ghogen commented Jun 10, 2022

Issue Description

-targets command-line option doesn't work when building a solution

Steps to Reproduce

MSBuild.exe -targets SomeSolution.sln

Expected Behavior

List the available targets in each project

Actual Behavior

Builds the solution

Versions & Configurations

Windows 10
MSBuild version 17.3.0-preview-22307-01+bfd80ab16 for .NET Framework

@ghogen ghogen added bug needs-triage Have yet to determine what bucket this goes in. labels Jun 10, 2022
@rainersigwald rainersigwald added the Area: Solution (.sln) Issues related to parsing .sln files or building solutions label Jun 13, 2022
@rainersigwald
Copy link
Member

In addition to "working on solutions at all", this should have a blurb about the dynamically-generated solution targets that delegate to all projects.

@benvillalobos
Copy link
Member

In addition to "working on solutions at all", this should have a blurb about the dynamically-generated solution targets that delegate to all projects.

Agreed, I had to dig into a metaproj with vs code to understand it more, and even then it wasn't easy to parse.

@rainersigwald rainersigwald added help wanted Issues that the core team doesn't plan to work on, but would accept a PR for. Comment to claim. and removed needs-triage Have yet to determine what bucket this goes in. labels Jun 16, 2022
@rainersigwald rainersigwald added this to the Backlog milestone Jun 16, 2022
@jrdodds
Copy link
Contributor

jrdodds commented Jul 30, 2022

The -targets and -preprocess switches are both documented as not executing a build process. However, both will exclude a solution file from their respective operations and then incorrectly build the solution file.

It seems like the first pass of a fix would be to not build when either of these two switches are present. If the file is a solution, then the operation isn't performed because it isn't supported but also no build is performed. I have a sense already of how to make this fix.

Should -targets support solutions? I'm not sure that I fully understand the comments from @rainersigwald and @benvillalobos but it seems the answer is 'Yes'.

Should -preprocess support solutions? Is -preprocess on a solution essentially the same output as setting MSBUILDEMITSOLUTION? Should a separate issue be created for the -preprocess switch with a solution?

@rainersigwald
Copy link
Member

Should -targets support solutions?

Yes. In addition to "listing all the targets", I'd like to see a special case for solutions that also says "We'll make up a target for any target name you specify and pass it to all of the projects in the solution, so this isn't an exhaustive list".

Should -preprocess support solutions? Is -preprocess on a solution essentially the same output as setting MSBUILDEMITSOLUTION? Should a separate issue be created for the -preprocess switch with a solution?

IMO yes, yes, and yes. But this isn't super high pri IMO; I'd be quite happy with "it just errors out and doesn't accidentally build"

@jrdodds
Copy link
Contributor

jrdodds commented Aug 1, 2022

@rainersigwald Thanks for the response. Please assign this issue to me.

I wasn't aware that it is now possible to pass a target to the solution that doesn't exist on the solution and that the solution will pass the target to all projects. I have had to work around this in the past. Now I understand the comment about the "dynamically-generated solution targets".

Thanks

@rainersigwald
Copy link
Member

It was implemented in #1497, I believe.

@jrdodds
Copy link
Contributor

jrdodds commented Aug 2, 2022

Some observations:
Given a sol.sln that contains projects a.proj and b.proj;

The ability to pass project name and target to the solution (e.g the following code) is documented.

msbuild sol -target:b:fred

The ability to pass any target to the solution and the solution will invoke the target on each project (e.g the following code) does not appear to be in the documentation.

msbuild sol -target:fred

There is an issue. The build will have an error if any of the projects in the solution don't provide the target. i.e. if 'fred' is a target in b.proj but not in a.proj, then a MSB4057 error will be reported on a.proj. The solution has project specific targets but doesn't know to skip non-existent targets.

@jrdodds
Copy link
Contributor

jrdodds commented Aug 6, 2022

@rainersigwald It may be helpful to split a new issue out from this issue:

Implementing -targets for solution files would remain with this issue.

@DerekSMorin
Copy link

Would this command also work with slnf ( solution filter files )?

Sorry for creating a duplicate issue, searching for "target" had way too many hits and I couldn't figure out how to search for what I wanted.

@rainersigwald
Copy link
Member

We should make sure it works for .slnf too, yes. I suspect that might happen "for free" when fixing .sln but there might be some more work required.

@jrdodds
Copy link
Contributor

jrdodds commented Mar 22, 2023

PR #8588 stops the incorrect behavior of building a solution when either -preprocess or -targets is provided.

Implementing -preprocess and -targets for solutions will be a separate PR on this issue.

@KalleOlaviNiemitalo
Copy link

Was this closed too soon? The description of #8588 says it fixes this "Partially".

@jrdodds
Copy link
Contributor

jrdodds commented Apr 8, 2023

Yes, this issue should be reopened.

The current PR 'fixes' the incorrect behavior of building the solution when a -preprocess or -targets switch is passed, but doesn't implement the switches for solutions.

@rainersigwald rainersigwald reopened this Apr 10, 2023
@rainersigwald
Copy link
Member

Whoops, didn't notice the keywords in the PR.

@jrdodds
Copy link
Contributor

jrdodds commented Jun 26, 2023

(Noting that #8908 is related to this issue.)

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 help wanted Issues that the core team doesn't plan to work on, but would accept a PR for. Comment to claim. triaged
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants