-
Notifications
You must be signed in to change notification settings - Fork 258
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
Nuget package update reformats config files poorly or creates unwanted config files #7180
Comments
The general trashing of formatting is the result of using XmlDocument or XDocument. Other than parsing the file as text I dont think there is a way to preserve all existing formatting in a config file. I would consider that a defect in either those two classes, or in the decision to use XML files for .net configuration. FWIW, the ability to add comments to XML makes it better than JSON for this purpose, but I would expect this to be sensible about how much needless pending change churn it creates. The creating of app.config files for projects that didnt have them and dont need them is a bug in nuget, as is the zero-change modification to an existing config file that causes pending changes in team explorer. Adding the binding redirect checkbox on the project property helps some, but is still kind of a bandaid. To get around this as fast as possible, currently I can search for app.config files in Solution Explorer and delete all the ones with a pending add, then use Undo Unchanged from this extension (where did |
@mishra14 - I'm sure you guys know how to do this stuff already, but if it helps address this issue faster, I figured out how to edit a part of the config file without wrecking the formatting of the rest of the file. Its not complete as far as adding/editing/removing specific assembly bindings (that code I think you would already have), but it does show how to avoid the unnecessary churn created from XmlDocument or XDocument. This is an example where I had it rewrite the assembly bindings section only. Note the element closures and line breaks in the rest of the file are preserved. |
@PatoBeltran is currently working on changing the code that reads xml files in NuGet. He might be better able to address this issue. |
@mishra14 @PatoBeltran - any info about this? |
I don't think his changes affect the web.config, but rather the NuGet.config files only. |
@nkolev92 - is the "Settings" tag appropriate for this as its not settings related? |
@nkolev92 - Also, this issue has had many reports on developer community and contrary to Alisa Gu's response, it is affecting all users of Visual Studio. Its not a Packages.Config specific thing either, as installation of packages by Package ref also will create/modify app and web.config files for binding redirects. |
NuGet itself does not modify the app/web config as part of the PackageReference restore/install (which is really restore in the background) workflow. So if there are changes, it's a different component. |
@nkolev92 - what is it that adds binding redirects to config files after/during package installation? What is it that adds app.config files to projects that didnt have/need them? I'm pretty sure I've seen that code and it is in the nuget client repo. EDIT: If you are telling me that package ref will install packages but not create binding redirects when necessary, then that is a different problem. I cant have software that compiles but has runtime issues due to missing redirects. That's going to be yet another entry in the list of 1000 cuts.. |
You are correct, nuget does do that, but only in the case of packages.config. See for example that code is in a VisualStudio, while NuGet PackageReference also works the same in msbuild and dotnet.exe.
I'm just saying it's not NuGet specifically that does that anymore, rather a different component. Which is why I tagged it as "packages.config" only. |
@nkolev92 - Tagging this as packages.config means we will have to continue to deal with this burden because while the nuget team "supports" packages.config there will not be any attempts to fix bugs that do not overlap package ref. A tool is only effective if it allows you to achieve more with a similar effort.
Not a great set of choices you all have decided to leave us with. Throwing an unexpected pile of work in front of someone who was using a tool you made is a foul thing to do. |
@heng-liu @zkat i have the same problem and it really annoys me. Every time before checkin i need to check each config file and undo changes to all config files that were unexpectedly changed. It also adds configs for library projects. If you have many projects in one solution it is really a nightmare. It takes extra efforts and time. It would be great if we can get some kind of feedback |
I tried the XDocument APIs, but seems none of them could keep the indent in one element(between attributes).
If we save the above file in path1, and load the file and save it to path2
Then the indent in path1 disappeared when loaded and saved in path2. So looks like we need to implement a fundamental function to keep the whitespaces in one element(between attributes). |
@heng-liu - I made a working POC a while ago |
Thanks @StingyJack ! |
Its a POC so I didnt bother with some of the niceties or adhering to any one particular style. I made it available to just about anyone to use however they wanted. But I didn't create this incredible time vampire of a defect described in the OP thats just been getting ignored by its creator. It seemed to me that it was not getting fixed because the creator did not know how to go about fixing it. For that I am willing to help unblock them, but I should not be asked have to take on the entire burden of fixing it, including the inevitable PR grief and likely denial of the same. Since you can add labels, I'm assuming you work for MSFT. I do not, so I'm not sure I'm even equipped to do this work since it may be inside VS. |
Hi @StingyJack Regarding the creation of app.config files for class libraries, feel free to create a new issue for that feature request so we can track it separately, as the majority of this issue is discussing whitespace changes. |
Team triage meeting: Regarding keeping whitespace in app.config and web.config files, after careful consideration, we have decided not to work on this issue due to high cost of implementation and the expectation that customers will continue to migrate to .NET (6+) and SDK style projects. |
@zivkan - A customer reported a problem to you 4.5 years ago, you finally get around to triaging it, and your response is to tell the customer to open a new ticket? And then leave an even older report open?
Wasnt this the hard part? This specific issue burned at least 100 hours of my time over a 2-3 year period with something that should have been caught and flagged by QC/QA, |
@zivkan : those of us still working on webform applications can't switch over to .net 7+ or SDK projects for everything (as SDK projects for webform seems to be off the menu dotnet/project-system#2670). |
The VS Feedback item has the original unredacted attachment illustrating the problem.
In this redacted example, you can see its removed the line breaks as well as changed the spacing before the closing element. Its changing the formatting of config files in this manner for projects that are not having any binding redirects added or changed, and for projects that aren't being targeted for the package update.
Its also creating new app.config files for projects that didnt have them and don't need them (class libraries).
All of these are a tedious venture to cleanup before checkin or submitting for code review. On larger solutions (> 50 projects) this can easily take an hour or more to clean up - every time a single package is updated in a project in the solution.
The text was updated successfully, but these errors were encountered: