Visual Studio 2010中:Properties.Settings retargetting项目的.NET Framework 3.5后破 [英] Visual Studio 2010: Properties.Settings broken after retargetting project to .NET Framework 3.5

查看:281
本文介绍了Visual Studio 2010中:Properties.Settings retargetting项目的.NET Framework 3.5后破的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经改变了项目的目标

  • 的.NET Framework 3.5

而不是

  • .NET Framework 4中。

该项目现在崩溃每当我试图访问设置:

  Settings.Designer.cs:

      返回((全球:: System.Drawing.Font)(本[DefaultFont]));
 

除了对'全球:: System.Drawing.Font)(本[DefaultFont]));

  

出错创造的applicationSettings / PromotionInventoryManagementSystem.Properties.Settings配置节处理程序:无法加载文件或程序集系统,版本= 4.0.0.0,文化=中性公钥= b77a5c561934e089或它的某一个依赖。该系统找不到指定的文件。 (C:\开发\ CasinoWindsor \推广Inventory\PromotionInventoryManagementSystem\PromotionInventoryManagementSystem\bin\Debug\PromotionInventoryManagementSystem.vshost.exe.config 8号线)

问题是,在 MyApp.exe.config 包含对.NET框架4.0( 4.0.0.0 ):

 < XML版本=1.0&GT?;
<结构>
    < configSections>
        < sectionGroup名=userSettings
              TYPE =System.Configuration.UserSettingsGroup,系统,
                    版本= 4.0.0.0,
                    文化=中性公钥= b77a5c561934e089>
 

此文件在每次构建产生,并根据 Settings.settings (一个XML文件中的内容没有提到 4.0 .0.0 的任何地方):

 < XML版本=1.0编码=UTF-8&GT?;
< SettingsFile的xmlns =htt​​p://schemas.microsoft.com/VisualStudio/2004/01/settingsCurrentProfile =(默认)GeneratedClassNamespace =PromotionInventoryManagementSystem.PropertiesGeneratedClassName =设置>
  <概况/>
  <设置>
 

还有设置code-隐藏文件( Settings.Designer.cs ),也没有提到 4.0.0.0 的任何地方:

 命名空间PromotionInventoryManagementSystem.Properties {


    [全球:: System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
    [global::System.$c$cDom.Compiler.Generated$c$cAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", 10.0.0.0)
    内部密封部分类设置:全球:: System.Configuration.ApplicationSettingsBase {

        私有静态设置defaultInstance =((设置)(全球:: System.Configuration.ApplicationSettingsBase.Synchronized(新设置())));

        公共静态设置默认{
            得到 {
                返回defaultInstance;
            }
        }
 

为什么产生 MyApp.exe.config 引用.NET 4.0(即 4.0.0.0 ),当该项目是不是4.0:

和设计师是不是4.0?

和一个更大的问题:

  

我要如何重新定位项目为的.NET Framework 3.5 的.NET Framework 4.0

解决方案

<一个href="http://stackoverflow.com/questions/6408308/application-settings-error-after-changing-target-framework-of-project">Found答案,删除的app.config

的app.config 自动根据 settings.settings 创建。 Visual Studio中没有构建它,即使它需要更新。

注意:清理并重建不会强制Visual Studio的清理和重建它

删除它,迫使Visual Studio的重建,它不动它。

i've changed a project to target

  • .NET Framework 3.5

rather than

  • .NET Framework 4.

The project now crashes whenever i try to access settings:

Settings.Designer.cs:

      return ((global::System.Drawing.Font)(this["DefaultFont"]));

With the exception on `global::System.Drawing.Font)(this["DefaultFont"]));

An error occurred creating the configuration section handler for applicationSettings/PromotionInventoryManagementSystem.Properties.Settings: Could not load file or assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The system cannot find the file specified. (C:\Develop\CasinoWindsor\Promotion Inventory\PromotionInventoryManagementSystem\PromotionInventoryManagementSystem\bin\Debug\PromotionInventoryManagementSystem.vshost.exe.config line 8)

The problem is that the MyApp.exe.config contains references to .NET Framework 4.0 (4.0.0.0):

<?xml version="1.0"?>
<configuration>
    <configSections>
        <sectionGroup name="userSettings" 
              type="System.Configuration.UserSettingsGroup, System, 
                    Version=4.0.0.0, 
                    Culture=neutral, PublicKeyToken=b77a5c561934e089">

This file is generated on every build, and it based on the contents of Settings.settings (an xml file that doesn't mention 4.0.0.0 anywhere):

<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="PromotionInventoryManagementSystem.Properties" GeneratedClassName="Settings">
  <Profiles />
  <Settings>

There's also the settings code-behind file (Settings.Designer.cs), that also doesn't mention 4.0.0.0 anywhere:

namespace PromotionInventoryManagementSystem.Properties {


    [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")]
    internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {

        private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));

        public static Settings Default {
            get {
                return defaultInstance;
            }
        }

Why is the generated MyApp.exe.config referencing .NET 4.0 (i.e. 4.0.0.0), when the project isn't 4.0:

and the designers aren't 4.0?

And the larger question:

How do i retarget a project to .NET Framework 3.5 from .NET Framework 4.0?

解决方案

Found the answer, delete app.config.

app.config is automatically created based on settings.settings. Visual Studio was not building it, even though it needed to be updated.

Note: Clean and rebuild doesn't force visual studio to clean and rebuild it

Deleting it, to force Visual Studio to rebuild, it fixed it.

这篇关于Visual Studio 2010中:Properties.Settings retargetting项目的.NET Framework 3.5后破的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆