Skip to content

Making package downgrade warnings an error by default. - #1329

Merged
livarcocc merged 3 commits into
dotnet:release/2.0.0from
livarcocc:package_downgrade_warning_as_error
Jun 14, 2017
Merged

livarcocc merged 3 commits into
dotnet:release/2.0.0from
livarcocc:package_downgrade_warning_as_error

Conversation

@livarcocc

Copy link
Copy Markdown
Contributor

@dotnet/dotnet-cli @srivatsn

@MattGertz for approval

Customer scenario

Making package downgrade warnings an error by default. This is being done in the SDK because we want this behavior for SDK based projects only.

Bugs this fixes:

#1310

Workarounds, if any

User can set this property themselves in their project file.

Risk

Low.

Performance impact

N/A

Is this a regression from a previous update?

N/A

Root cause analysis:

N/A

How was the bug found?

Planned feature.

@livarcocc livarcocc added this to the 2.0.0 milestone Jun 9, 2017
@livarcocc

Copy link
Copy Markdown
Contributor Author

@dotnet-bot Test Windows_NT Debug
@dotnet-bot Test Windows_NT Release

@livarcocc
livarcocc force-pushed the package_downgrade_warning_as_error branch from b501efc to 4062e88 Compare June 9, 2017 16:04
@livarcocc

Copy link
Copy Markdown
Contributor Author

@MattGertz for approval.

restoreCommand
.Execute($"/p:RestorePackagesPath={packagesFolder}")
.Should().Fail()
.And.HaveStdOutContaining("MSBUILD : error NU1605: Detected package downgrade");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we limit this to NU1605? It's more test debt for loc case otherwise.

<DebugSymbols Condition="'$(DebugSymbols)'==''">false</DebugSymbols>
<CheckForOverflowUnderflow Condition="'$(CheckForOverflowUnderflow)'==''">false</CheckForOverflowUnderflow>

<WarningsAsErrors>NU1605</WarningsAsErrors>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't overwrite existing warnings as errors

<DebugSymbols Condition="'$(DebugSymbols)'==''">false</DebugSymbols>
<CheckForOverflowUnderflow Condition="'$(CheckForOverflowUnderflow)'==''">false</CheckForOverflowUnderflow>

<WarningsAsErrors>NU1605</WarningsAsErrors>

@nguerrera nguerrera Jun 10, 2017 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is disconcerting to me that we're going to be passing NU1605 to the compiler as well as honoring it in nuget.

I had a look and Roslyn will ignore unrecognized identifiers, but fsc will not. This is going to break F#:

FSC : error FS0241: 'NU1605' is not a valid integer argument [D:\Temp\wae\fsc\fsc.fsproj]

@srivatsn, @rrelyea, I don't think we should be passing the same property to the compiler and nuget.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason we decided to do that was because the same properties are used by analyzers as well and for C#\VB those fields can have arbitrary error codes. From a user standpoint - it's easier to think of it as one place to suppress warnings coming from build than have one for each tool (given there's UI for these properties).

We hadn't considered F#. Should we maybe default these only for C#\VB?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that not doing this for F# is the right approach. This is all package resolution and it should behave the same across all languages. However, it might be the easier way for now. @KevinRansom, is there a reason why fsc does not behave he same way as csc and vbc and ignores unknown identifiers? Would it be possible to make it do so? Also, @srivatsn, is there another property that we could use if none of the alternatives above work?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can always make up a new property but there's no UI for anything else.

@nguerrera nguerrera left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above

…done in the SDK because we want this behavior for SDK based projects only.
@livarcocc

Copy link
Copy Markdown
Contributor Author

@dotnet-bot Test OSX10.12 Debug
@dotnet-bot Test OSX10.12 Release

@livarcocc
livarcocc merged commit 5ab6498 into dotnet:release/2.0.0 Jun 14, 2017
@livarcocc
livarcocc deleted the package_downgrade_warning_as_error branch June 14, 2017 02:25
IsSdkProject = true
};

testProject.AdditionalProperties.Add("WarningsAsErrors", string.Empty);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this look like in XML? An empty element?

@MChartier

MChartier commented Aug 23, 2017 •

Copy link
Copy Markdown

This created some confusion for my team after installing the latest .NET Core SDK. When checking our project settings, they did not seem configured to treat any warnings as errors, so it took awhile for us to understand what was happening and longer to find a workaround for the build issue we were suddenly seeing for previously working commits. Some of our VSTS build definitions are still broken, in fact, without even having been updated.

We want to be able to treat "downgrades" as warnings, not as errors, because we are still in a rapid prototyping phase and are currently taking a number of dependencies on prerelease packages. We have two packages which are published to our private feed from the same solution, one of which depends on the other within the solution. So when both are included by a third package, there is a conflict between the version we include (1.0.0-x prerelease), and the version that the dependent package expects (>= 1.0.0). Until recently, this was working fine.

This change was pretty confusing and has resulted in failures which have been difficult to diagnose and resolve. I think there should be some easily discoverable developer guidance on this.

Update: I still haven't succeeded in getting my VSTS build definitions to work. I've attempted to work around the "default" treatment of NU1605 as an error by setting a different warning code to be treated as an error (so that the value is not the empty string), but it is still being treated as an error in the 'dotnet build' step (though not in the 'dotnet restore' step, where it is treated as a warning.

@davidfowl

Copy link
Copy Markdown
Member

So when both are included by a third package, there is a conflict between the version we include (1.0.0-x prerelease), and the version that the dependent package expects (>= 1.0.0). Until recently, this was working fine.

Can you explain your dependency graph a bit more?

@MChartier

Copy link
Copy Markdown

Sure. I had a solution containing projects A and B, which had package versions defined as "1.0.0" in the solution. Project A references Project B, so A depends on B version 1.0.0.

In my VSTS build, I used 'dotnet pack' with the --version-suffix parameter to create prerelease Nuget packages for each of these projects, with version numbers of the form '1.0.0-<BUILD_NUMBER>'.

In another solution, project C consumes the Nuget packages for both A and B. So C consumes prerelease versions of A and B, but A depends on the "release" version 1.0.0 (since it depends on the other project directly in its solution). So because C consumes a prerelease version of B published to Nuget, there is a package downgrade conflict with A (since 1.0.0-x < 1.0.0).

I'm quite aware this isn't a best practice, but it's allowed me to iterate quickly and consume the latest changes in my private packages without having to manage package version numbers. Up until recently, it had (correctly) resulted in a compile-time warning, but not blocked my build, and everything worked as I needed it to.

I am not in need of a workaround, as I've already spent some hours updating all of my packages to have properly versioned release packages to get around this. I want to call out, though, that the workaround described on this page ("User can set this property themselves in their project file.") did not work for me. No matter how I configured the settings for treating warnings as errors, my builds in VSTS broke; I could make the problem go away on my local desktop in Visual Studio, but not when using the dotnet CLI in my build definitions.

I don't think it's good practice to hard-code compile-time warnings to be treated as errors, and I hope that this approach is not taken again in the future; these are breaking changes to existing supported workflows, which translates to lost dev time and reduced trust in the platform.

@FransBouma

FransBouma commented Sep 15, 2017 •

Copy link
Copy Markdown

It's unfortunate this was done, because NuGet currently still hasn't implemented proper pre-release versioning wildcards. We now run into this problem which is similar to what @MChartier sees. I'll try to explain.

We generate csproj files which reference the nuget packages of the version that generated the code. So if I generate a csproj using 5.3.0, I get a csproj which references nuget packages v5.3.0. If the code is generated with a prerelease, or e.g. a hotfix build (which is a pre-release before the actual 3rd digit bump, so v5.3.1-hotfix-builddate is a hotfix build of v5.3.0 and a pre-release of the official 5.3.1), it still uses the official version, so if I generate code with v5.3.1 hotfix build I get a csproj which references packages v5.3.1.

If I then on nuget have v5.3.1 hotfix builds (using version 5.3.1-hotfix-builddate) I get a downgrade warning. However it fails now with an error thanks to this PR because the csproj references 2 packages, A and B, where B has a dependency on A-5.3.1.

I first thought to include a general wildcard in the dependency data for package B, but that's not implemented in nuget (for years now NuGet/Home#912) and the only workaround I see is to specify the dependency as (5.2.99, 5.4.0) for B, which is limiting to say the least and likely for some people not sufficient.

IMHO this hard-coded fail on error is too rigid unless Nuget implements their issue 912. Which seems to be a long way off.

(edit) and what is the 'workaround' here if we want to fix this? Please don't say 'you can augment the pre-release version in the generated csproj' as that's a lot of work: we then have to bleed the version of the package into an asset elsewhere which has no notion of a package specific release state (i.e. prerelease or rtm).

User can set this property themselves in their project file.

E.g. what is the property to set and what is the impact of that?

@Boggin

Boggin commented Oct 30, 2017

Copy link
Copy Markdown

User can set this property themselves in their project file.

I'm almost certain there's no such system for downgrading an Error to a Warning.

@nguerrera

nguerrera commented Oct 31, 2017 •

Copy link
Copy Markdown
Contributor

@FransBouma @Boggin

This change just makes the default value of WarningsAsErrors include NU1605.

You still have full control to override the default. If you want it to remain a warning, you can set <WarningsAsErrors /> in the project file.

@nguerrera

Copy link
Copy Markdown
Contributor

You can also use VS to adjust the project: Project Properties -> Build -> Treat Warnings As Errors -> Select None, or remove NU1605 -> Save project.

@Boggin

Boggin commented Nov 1, 2017 •

Copy link
Copy Markdown

@nguerrera Thanks for clearing up my ignorance, it's much appreciated.

I found the following two lines are added to the .csproj when you use VS to update the project (as shown above):

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    …
    <TreatWarningsAsErrors>false</TreatWarningsAsErrors>
    <WarningsAsErrors />
</PropertyGroup>

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants