简体   繁体   English

重新生成 Settings.settings

[英]Regenerate Settings.settings

I am in the process of refactoring a project that was, to my chagrin, written in Visual Studio.我正在重构一个项目,令我懊恼的是,该项目是用 Visual Studio 编写的。 I come from a Linux background and find Visual Studio a catacomb of disempowering menus.我来自 Linux 背景,发现 Visual Studio 是一个令人沮丧的菜单的地下墓穴。

I am trying to move a Settings.settings file from one solution into another.我正在尝试将Settings.settings文件从一个解决方案移动到另一个解决方案。

Copying all the text from Settings.Designer.cs has produced the desired compile time functionality, but I can't seem to use the gui for changing properties.Settings.Designer.cs复制所有文本已经产生了所需的编译时功能,但我似乎无法使用 gui 来更改属性。 The gui doesn't show any properties, unlike my source project.与我的源项目不同,该 gui 不显示任何属性。 I also worry that my changes will disappear at VS's whim (when it regenerates this file).我还担心我的更改会随着 VS 的突发奇想而消失(当它重新生成此文件时)。

How can I regenerate these properties from my existing configuration file?如何从现有的配置文件中重新生成这些属性?

You can delete the .Designer.cs file then exclude the .settings file from the project and include it again.您可以删除 .Designer.cs 文件,然后从项目中排除 .settings 文件并再次包含它。 Then the .designer file is regenerated.然后重新生成 .designer 文件。

In between, make sure to click on the Show all files button, otherwise you cannot see the file you have just excluded from your project.在这两者之间,请确保单击“显示所有文件”按钮,否则您将看不到刚刚从项目中排除的文件。

I just had to do a similar thing.我只需要做类似的事情。

What worked for me is this:对我有用的是:

  1. Add a settings file using 'Add....' Name it Settings.settings使用“添加...”添加设置文件,将其命名为 Settings.settings
  2. Move the settings file to the Properties directory.将设置文件移动到属性目录。 (Just grab and move it.) (只需抓住并移动它。)
  3. Now since that's an empty settings file, copy the older settings file (the one you want to move) to the same area, overwriting the one that was just created.现在,由于这是一个空设置文件,请将旧设置文件(您要移动的设置文件)复制到同一区域,覆盖刚刚创建的设置文件。
  4. Run the custom tool to recreate Settings.Designer.cs运行自定义工具以重新创建 Settings.Designer.cs

My problem was that I got stuck on trying to copy both the Settings.settings file and the Settings.Designer.cs.我的问题是我在尝试复制 Settings.settings 文件和 Settings.Designer.cs 时遇到了困难。 That was a no-go.那是不行的。

This is an old question.这是一个老问题。 Now seems like none of the above answers apply to VS 2019, and yet this problem continues to exist in some fashion.现在似乎上述答案都不适用于 VS 2019,但这个问题仍然以某种方式存在。 I deleted and excluded and re-added until I could no longer remember what I did.我删除并排除并重新添加,直到我不再记得我做了什么。 But in the end, it started working.但最终,它开始起作用了。 Looking at what VS added to my csproj file, I think the key is that you need this:查看 VS 添加到我的 csproj 文件中的内容,我认为关键是您需要这个:

<Compile Update="Properties\Settings.Designer.cs">
  <DesignTimeSharedInput>True</DesignTimeSharedInput>
  <AutoGen>True</AutoGen>
  <DependentUpon>Settings.settings</DependentUpon>
</Compile>

According to this ASP.NET post , you can do this根据this ASP.NET post ,您可以这样做

If you edit the settings.settings file and the value in the settings.designer.cs file does not change, you can delete the settings.designer.cs file and then right-click on the settings.settings file and select "Run custom tool".如果编辑settings.settings文件,而settings.designer.cs文件中的值没有改变,可以删除settings.designer.cs文件,然后右键settings.settings文件,选择“运行自定义工具” ”。 That will regenerate the settings.designer.cs file.这将重新生成 settings.designer.cs 文件。

you can importe settings from an other project.您可以从其他项目导入设置。 Simply Copy settings.setings from solution explorer then paste it in the other project.只需从解决方案资源管理器中复制 settings.settings,然后将其粘贴到另一个项目中。 (same way you can use import over copy/paste) visual studio will generate automaticaly the config for (app.config). (同样你可以通过复制/粘贴使用导入)Visual Studio 将自动生成(app.config)的配置。

first project第一个项目

Second project第二个项目

Second project第二个项目

next when you click on designer visual studio should notify you all properties will be added to your app.config (and make it visible in you designer)接下来,当您单击设计器时,Visual Studio 应该会通知您所有属性都将添加到您的 app.config 中(并使其在您的设计器中可见)

notification通知

All I had to do was to delete and exclude the file "settings.designer.cs".我所要做的就是删除并排除文件“settings.designer.cs”。 There was no problem with it in vs2019 and earlier versions.在vs2019及更早的版本中没有问题。 The solution of deleting the file was not in the intellisense.删除文件的解决方案不在智能感知中。

In the project file, the Settings.settings must be added as Content for it to work (in my project it was added as None for some reason and then the code never got updated).在项目文件中,必须将Settings.settings添加为Content才能使其工作(在我的项目中,由于某种原因它被添加为None ,然后代码从未更新)。

The settings block in your project file should look like this:项目文件中的设置块应如下所示:

<ItemGroup>
  <Content Include="Properties\Settings.settings">
    <Generator>SettingsSingleFileGenerator</Generator>
    <LastGenOutput>Settings.Designer.cs</LastGenOutput>
  </Content>  
  <Compile Update="Properties\Settings.Designer.cs">
    <DesignTimeSharedInput>True</DesignTimeSharedInput>
    <AutoGen>True</AutoGen>
    <DependentUpon>Settings.settings</DependentUpon>
  </Compile>
</ItemGroup>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM