Skip to content

Take $(TreatWarningsAsErrors) into account - #1224

Merged
ltrzesniewski merged 1 commit into
masterfrom
TreatWarningsAsErrors
Nov 9, 2023
Merged

ltrzesniewski merged 1 commit into
masterfrom
TreatWarningsAsErrors

Conversation

@ltrzesniewski

@ltrzesniewski ltrzesniewski commented Nov 4, 2023 •

Copy link
Copy Markdown
Member

I figured maybe Fody should take $(TreatWarningsAsErrors) into account, and emit errors instead of warnings when this property is set to true.

This PR adds a FodyTreatWarningsAsErrors property which is set to $(TreatWarningsAsErrors) by default, but can be overridden if needed.

This is a suggestion, tell me what you think. This could be a breaking change to existing users.

Note that the same outcome can be achieved without this PR by setting $(MSBuildTreatWarningsAsErrors) to true - in that case any warning emitted during the build will become an error, not just Fody warnings.

(sorry for all the edits, I must have pressed a shortcut and the PR got submitted before I finished writing the summary)

Comment thread Fody/Fody.targets Resolved
@tom-englert

Copy link
Copy Markdown
Member

I can't remember seeing warnings from Fody for a long time now, so for me this would be OK.

@ltrzesniewski

Copy link
Copy Markdown
Member Author

I regularly see the warning from PropertyChanged.Fody which says that there's an OnFooChanged method but no Foo property. That's the main reason I wrote this.

@SimonCropp

Copy link
Copy Markdown
Member

if we take this approach, and someone hits one of these and has msbuild treatwarningsaserrors, can they still suppress fody warnings?

@tom-englert

Copy link
Copy Markdown
Member

@SimonCropp yes, you can always set FodyTreatWarningsAsErrors to false:

<FodyTreatWarningsAsErrors Condition="$(FodyTreatWarningsAsErrors) == ''">$(TreatWarningsAsErrors)</FodyTreatWarningsAsErrors>

@ltrzesniewski

ltrzesniewski commented Nov 9, 2023 •

Copy link
Copy Markdown
Member Author

@SimonCropp not sure which property you're talking about, so to clarify:

  • TreatWarningsAsErrors: you can override this one with FodyTreatWarningsAsErrors
  • MSBuildTreatWarningsAsErrors: you can't override this one (the PR would have to lower Fody warnings into info messages, but that wouldn't be something we want I think)

@SimonCropp

Copy link
Copy Markdown
Member

in that case i have no objections.

@ltrzesniewski
ltrzesniewski merged commit 48c3bfc into master Nov 9, 2023
@delete-merged-branch
delete-merged-branch Bot deleted the TreatWarningsAsErrors branch November 9, 2023 11:41
@ltrzesniewski

ltrzesniewski commented Nov 9, 2023 •

Copy link
Copy Markdown
Member Author

Fo some reason the integration test fails on mac after the merge. It doesn't look to be related to this PR though at first glance. 🤔

@ltrzesniewski

Copy link
Copy Markdown
Member Author

Ok, it worked on the third try ¯\_(ツ)_/¯

I noticed this PR only works for warnings emitted by the weavers though. The integration test emits a "Weavers should reference at least the current major version of Fody" warning which is not turned into an error. I suppose I should turn warnings emitted by Fody itself into errors as well (and set FodyTreatWarningsAsErrors to false for the integration test).

@ltrzesniewski

Copy link
Copy Markdown
Member Author

Regarding my previous comments:

  • Integration tests did not declare a dependency to their in-solution weaver, so would sometimes fail to build if that project wasn't built on time. I added the missing dependencies.
  • Integration tests were setting TreatWarningsAsErrors to true too late (after FodyTreatWarningsAsErrors was set). I added an explicit line which sets FodyTreatWarningsAsErrors to false there as we actually expect Fody warnings.
  • Warnings emitted by Fody itself are correctly turned into errors when needed.

So, everything should be fine now. I also mentioned FodyTreatWarningsAsErrors in the docs.

@ltrzesniewski ltrzesniewski added this to the 6.8.1 milestone May 15, 2024
@GeertvanHorrik

Copy link
Copy Markdown
Member

This one bit me since we do write warnings from our weavers when weaving, but they are sometimes "unsolvable". Now the builds are failing, but will using FodyTreatWarningsAsErrors to fix back the old behavior.

@ltrzesniewski

Copy link
Copy Markdown
Member Author

Well, sorry about that. On my side, I wanted for people to pay attention to warnings. 😅

Are you talking about some internal weavers? I hope using FodyTreatWarningsAsErrors is ok for you. In any case I'm open for discussion if you need anything else.

@GeertvanHorrik

Copy link
Copy Markdown
Member

Yes, just tested, that works great. I think overall this is a great improvement. We can still disable it on the few projects that cause these warnings as errors :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants