Visual Studio keeps adding blank lines

不羁岁月 提交于 2020-01-05 12:02:51

问题


I'm using Visual Studio 2008 for an ASP .Net application, and Visual Studio keeps adding blank lines to my aspx file whenever I save, switch to design mode and back to code view, switch to split mode, or switch between files. Before I save, I will have:

                        </ContentTemplate></asp:UpdatePanel>
                    </ContentTemplate>
                </ajax:TabPanel>
            </ajax:TabContainer>

Then, it will magically transform into:

    </ContentTemplate></asp:UpdatePanel>


</ContentTemplate>















</ajax:TabPanel>
                    </ajax:TabContainer>

I know it's mostly an aesthetics issue, but it's also adding 17 lines of nothing to each tab container (and making the file that much longer to scroll through) and it's very annoying. I've checked that I don't have a misplaced quotation mark, there's no misaligned tags earlier in the file, any ideas?


回答1:


The only time I've seen Visual Studio do something close to this is when the XML/HTML in question is invalid, for example you are missing a closing tag somewhere.




回答2:


I can't say I've ever experience this with any Visual Studio yet, but try this

Ctrl-E, D command will automatically reformat the document. (Assuming C# Development Enviroment)

Ctrl-K, Ctrl-D for Web Development Enviroment

If the document remains as it is with the incorrect spacing then the auto format is the problem. Simple disable the auto-format inside Options->Text Editors->HTML->Formatting




回答3:


For reasons unknown tab container appears to temporarily render in design environment with long string which seems to cause insertion of blank lines with default settings. Turing off the tag wrapping, seemed to work for me.

Tool/Options/

[Show all settings]

Text Editor/HTML

Wrap tags when exceeding specified lenght

If any interested.




回答4:


I had the same problem and none of the previous answers here solved it; but I found the solution here: https://github.com/Microsoft/vscode/issues/12076. Go to the .editor.config file and set insert_final_newline = false (or simply remove that line).



来源:https://stackoverflow.com/questions/77957/visual-studio-keeps-adding-blank-lines

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!