msbuild icon indicating copy to clipboard operation
msbuild copied to clipboard

MSB4011 is not suppressable by MSBuildWarningsAsMessages

Open rainersigwald opened this issue 6 years ago • 12 comments

Originally reported at https://developercommunity.visualstudio.com/content/problem/400893/using-msbuildwarningsasmessages-in-directorybuildp.html.

I have added Directory.Build.props to the same folder as my solution with content:

<Project>
<PropertyGroup> 
<MSBuildWarningsAsMessages>MSB4011</MSBuildWarningsAsMessages>
</PropertyGroup>
</Project>

The problem is that I still get the MSB4011 warnings when I compile.

I know that file is found because if I change the <PropertyGroup> tag to <PropertyGroup1>, I get an error when compiling.

Why isn't it working?

I am using visual studio professional 2017, 15.9.3. The projects are C++.

rainersigwald avatar Jan 02 '19 20:01 rainersigwald

I think this is happening for reasons related to #3295: the warning path for evaluation-related warnings is distinct from normal execution-time warnings.

In this case, the final value of MSBuildWarningsAsMessages can't be known mid-evaluation, so I'm not sure what could be done to fix this. We could maybe inspect the current value just before logging a warning, but that seems heavy-handed.

rainersigwald avatar Jan 02 '19 21:01 rainersigwald

Smallest repro I could think of: repro.zip

rainersigwald avatar Jan 02 '19 21:01 rainersigwald

Some warnings are logged by the same code that parse the codes to suppress in your Directory.Build.props. To suppress this warning (not recommended if you can just fix the double import) you can use the /nowarn command-line argument for builds run via msbuild.exe. But there is no way to suppress it in Visual Studio.

jeffkl avatar Jan 03 '19 17:01 jeffkl

It's impossible to avoid this warning when using new SDK-style projects if T4 templates are to be transformed during an msbuild build because the template targets must be included after the CSharp targets, and with SDK-style projects the CSharp targets get automatically included at the end of the csproj. I'd love to know of any workaround for this double-include, or at least how to get rid of this warning in the IDE

botrif avatar Feb 08 '19 22:02 botrif

@botrif I'm not sure I understand the whole situation, but can you expand the Sdk imports into their explicit form, like:

<Project>
    <Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" />

    <PropertyGroup>
        <TargetFramework>net46</TargetFramework>
    </PropertyGroup>

    <Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />

    <Import Project="T4 stuff" />
</Project>

?

rainersigwald avatar Feb 12 '19 15:02 rainersigwald

We are facing the same problem, but we are trying to make this warnings as error to stop this from happening earlier.

alexdrl avatar Feb 21 '19 08:02 alexdrl

We are also hitting the same issue. This is really discouraging.

bhupeshpant19jan avatar Mar 24 '20 21:03 bhupeshpant19jan

Same issue here.

Any chance suppressing this warning (or any MSB... for that matter) will be featured?

Full issue here (self-explanatory) : https://docs.microsoft.com/en-us/answers/questions/823721/visual-studio-34msb401134-build-warning-i-want-to.html

Would something similar to #pragma once reasonable for property sheets?

lapinott avatar Apr 28 '22 11:04 lapinott

It seems odd that this is special cased to not be suppressible? We're also using our props for dependency management across projects, those projects reference each other, so I don't think we can work around having them included multiple times.

So these warnings are just noise masking more important warnings in VS.

michael-hawker avatar May 11 '22 17:05 michael-hawker

There is a fundamental problem I see here. If one wants to override a default target of the standard build process it is necessary to explicitly add <Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" /> and after that define what is to be overridden as outlined here. However, this line results in a MSB4011 warning. If you're working in an environment where warnings are automatically turned into errors by the build system you cannot override default MSBuild targets.

ackh avatar Sep 08 '22 09:09 ackh

If one wants to override a default target of the standard build process it is necessary to explicitly add <Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" /> and after that define what is to be overridden as outlined here. However, this line results in a MSB4011 warning.

That should not be true--@ackh did you add that explicit import without removing the Sdk="Microsoft.NET.Sdk from the top-level <Project> element?

The docs on this weren't super clear so I submitted MicrosoftDocs/visualstudio-docs#8444.

rainersigwald avatar Sep 08 '22 14:09 rainersigwald

@rainersigwald You are right, I simply overlooked that I need to remove Sdk="Microsoft.NET.Sdk" from the Project node. Doing so prevents my problem entirely. Thanks for your quick reaction to my comment!

ackh avatar Sep 08 '22 14:09 ackh