-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Treat files copied from a NuGet package content as generated #55992
Comments
Not quite sure what the ask is here. The compiler considers code in a NuPkg file to be a part of the compilation, as if the code existed in the users project. This has been the design since basically the beginning. What is the motivation for wanting to change this now? I'm very reluctant to introduce yet another type of code file over our current normal + generated code combination.
I don't see this as a particularly compelling argument. This has been true for many years now and it's failed to show up as a significant source of user feedback. It's also true for source generated files. Customers can work around this by using a Customers who distribute code via NuPkg are opting for a hard scenario here. It's expected that their code will need to be coded to a very high bar to be generally usable. |
Indeed, |
I'm re-opening since |
Any movement on this? If not I might just continue forward with fixes upstream. The issue with this though is if the upstream package doesn't use the same analyzer rules and fail on warning. Then a build breaking change could happen at any time. |
I'm still unclear on what the problem is here. The issue lacks specifics on a repro as do the linked issues. Think we need to have a concrete understanding of what the problem is to make any progress. |
I am enabling Code Analysis Analyzers on msbuild. MSBuild has a dependency in Because MSBuild has So to fix those errors, we either fix the errors upstream and then update the nuget package; or find a way to supress the warnings for those files which are provided as a part of the nuget package. |
Okay, I still don't see how this is a C# compiler bug though. The compiler is being passed files, an editor config, and is applying the rules as asked to those files. I don't understand the action being requested here. |
The fix suggested above was to apply a change to the
This did not work. I am unsure how we can exclude files provided from a nuget package from code analysis so our builds don't fail. |
@elachlan Just to confirm, the core issue you are facing is highlighted in dotnet/msbuild#7187 (comment), correct? Few points to note:
|
@mavasani thank you for the explanation an example project. It has been incredibly helpful! It looks like I will need to rearchitect the analyzers in MSBuild to move back to .editorconfig from globalconfigs. |
Having to use both Can't we get |
I think that is being discussed in #47384 ? |
@elachlan There is no source generators involved for this issue I believe. |
.editorconfig cannot apply entries to files outside the directory cone it resides in. We shouldn't violate the core principles of .editorconfig for this requirement. |
@mavasani Would it be possible to get it via That way we're not violating how .editorconfig works currently (ie, it doesn't apply to parent directories), unless it was explicitly specified (considered as a new non-breaking feature) |
@elachlan One way to avoid repetitive entries for each rule ID in both your .editorconfig and .globalconfig would be to specify the below entry in .globalconfig, which disables all analyzers by default in the project: dotnet_analyzer_diagnostic.severity = none You can then specify |
I don't think so. The moment we allow .editorconfig to specify sections that apply to files outside its directory cone with |
Ideally, I'd like to exclude the source files provided via the nuget package from the global rules. That way the rules are kept centralised in the globalconfig (the file which is designed for analyzer rules). If there were some sort of syntax like the filter for editorconfig, it would help achieve that. Alternatively, just don't apply code analysis rules form globalconfigs to source files which are provided by nuget. I do understand that the documentation says that AnalyzerConfig files are "options that apply to all the source files in a project, regardless of their file names or file paths". but my feeling is that if the file is essentially "locked" then I cannot change it, so the analyzer becomes a bit of a hindrance. I can see how it would be helpful for projects that would run security based code analysis, so that any code that is included is scanned before build. An escape hatch for this would be incredibly useful, especially if it was targeted. |
@elachlan This is the ideal behavior I'd want, but as far as I understand, the issue here is that the compiler is passed source files, and it doesn't know whether it comes from NuGet or not. For the security analyzers, it's not an issue at all if the compiler was able to determine if the file passed comes from NuGet. All security analyzers are configured to analyze generated code, while most of non-security analyzers doesn't analyze generated code. |
An idea (which could be bad but may inspire others to come up with a better resolution): <PackageReference Include="PackageName" CopyContentToRoot="true" /> This will cause content files to be copied in whatever directory msbuild is invoked from, and these files will now be applicable to (this won't be a roslyn thing) |
Yes, this is the core issue here. You want to apply certain configuration to a group of files, that are no different to compiler than files coming from random directories in your file system. I don't believe we should introduce any notion in the compiler or editorconfig/globalconfig files to specially treat source files coming from NuGet package. |
Adding @chsienki, who might have more context on whether the feature being requested in #55992 (comment) is even technically possible. My gut feel says it is not, but Chris is the expert here. |
Correct. There was a lot of discussion early on about how to handle files in NuPgk and the decision was it is just source on disk. It is nothing special (even if we wanted it to be). If the developer puts NuPkg root such that an |
Closing this as by design. From the compiler point of view, nuget source files are just source files and should be treated the same way. I'm not sure how we'd even determine if a source file did come from a nuget package, as at the point of compilation they're effectively just regular files on disk. We have existing mechanisms that allow you to address the issues raised here. An alternative to using globalconfigs is to configure nuget to restore within your project directory. That way you can configure it via regular |
#7571) Relates to #7174 https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1518.md The two remaining warnings/suggestions are from RoslynImmutableInterlocked pulled in from Microsoft.CodeAnalysis.Collections in Microsoft.Build.Framework. Solution for the warnings from the nuget package is outlined in dotnet/roslyn#55992
When referencing a NuGet package with
<IncludeContentInPack>true</IncludeContentInPack>
, any warnings in that package can break the build. I think this should be treated in a special way (if possible).There are two kind of issues here:
TreatWarningsAsErrors
is true? Not sure. I'd be okay with keeping the current behavior for this one.The text was updated successfully, but these errors were encountered: