- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个将用户设置存储在标准 user.config 文件中的 C# 应用程序。
这显然位于以应用程序版本号命名的目录中,即
My_App/1.0.0.0/user.config
成功升级到我的应用程序的新版本 (1.0.0.1) 后,v1.0.0.0 的设置被复制并保存到新版本 1.0.0.1。这是简单的部分。
现在我想在升级后删除这个之前的版本目录1.0.0.0
我意识到目录的路径不能硬编码,因为位置因环境而异。
我一直在寻找使用:
using System.Configuration;
...
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal);
MessageBox.Show("Local user config path: {0}", config.FilePath);
它立即抛出一个错误,我需要添加:
using EnvDTE;
现在我有错误:
CS0117“ConfigurationManager”不包含“OpenExeConfiguration”的定义
CS0103 当前上下文中不存在名称“ConfigurationUserLevel”
CS1061“Configuration”不包含“FilePath”的定义,并且找不到接受“Configuration”类型的第一个参数的扩展方法“FilePath”(是否缺少 using 指令或程序集引用?)
有解决办法吗?
否则每次更新都会创建一个新目录,虽然每个目录只有 1kb,但让它们都挂载起来似乎很荒谬。
另外,我的应用程序没有安装在用户系统上,它都是直接从分布式.exe运行
更新 1
使用 EnvDTE 添加错误;根据评论删除。
CS0246 找不到类型或命名空间名称“Configuration”(是否缺少 using 指令或程序集引用?)
CS0103 当前上下文中不存在名称“ConfigurationManager”
CS0103 当前上下文中不存在名称“ConfigurationUserLevel”
更新 2
我以为我可以通过以下方式到达某个地方:
string path = Application.LocalUserAppDataPath;
MessageBox.Show(path);
相反,但这只是在我的原始路径旁边创建了一条新路径,其中有一个空的 <Program Version>
目录格式为:
<Company Name>/<Program Name>/<Program Version>
在实际user.config
路径 <Program Name>
添加了一个哈希字符串以形成类似于:
<Program Name.exe_Url_aqod5o1hapcyjk3ku1gpyynhem0mefle>
我会假设这个散列不是一个常量,并且在机器和安装之间确实有所不同
更新 3
我终于能够检索到 user,config
的确切路径像这样的文件:
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal);
MessageBox.Show(config.FilePath);
using System.Configuration
没有工作,我没有意识到它在代码中以稍微暗淡的颜色显示,因为它没有被引用,所以我通过右键单击资源管理器中的解决方案将其添加为引用。
现在config
包含 user.config
的完整路径在我运行 Windows 10 的情况下的文件:
<DRIVE LETTER>\Users\<USER NAME>\AppData\Local\<Company Name>\<Program Name>\<Program Version>\user.config
我需要操纵 config
绳子并爬出 <Program Version>
目录 & 到 <Program Name>
目录以查看其下是否有除当前 <Program Version>
以外的任何目录目录,如果有,我需要删除它们。
更新 4
好的,现在真的有进展了。我操纵了 filePath 字符串以达到 <Program Version>
的级别 parent 并使用此代码:
string FullfilePath = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal).FilePath;
string ProgNamefilePath = Path.GetFullPath(Path.Combine(FullfilePath, @"..\..\"));
Directory.Delete(ProgNamefilePath, true);
//MessageBox.Show(ProgNamefilePath);//For Testing Purposes
我可以删除这个目录下的所有目录,太棒了。
不,我卡住了,因为我不想删除与 <Program Version>
有关的所有目录但只有与当前版本不匹配的版本。
Application.ProductVersion;
最佳答案
一个不眠之夜思考这个问题并尝试考虑其他途径,我终于想到了这个并且它有效。
可能有更简洁的方法来做到这一点,但无论如何......
我可以将它放在代码的最高位置,以便在编码升级时希望对我自己来说非常明显,我把它放在:
public class MainForm : Form
{
//***********************************
//***********************************
//**** THIS RELEASE IS v1.0.0.1 ****
//***********************************
//****** REMEMBER TO EDIT THIS ******
//***********************************
const string DeleteThisVersionDirectory = "1.0.0.0"; //**** Set this to the <Program Version> Directory to be Deleted on Upgrade, usually version prior to new release. ****
//***********************************
//***********************************
您可以看到它直接位于 Form
下可见性打开。
然后我创建了这个方法:
private void ApplicationUpdate()
{
string FullfilePath = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal).FilePath;
string VersionDirectoryfilePath = Path.GetFullPath(Path.Combine(FullfilePath, @"..\..\" + DeleteThisVersionDirectory));
if (Properties.Settings.Default.UpdateSettings)
{
Properties.Settings.Default.Upgrade();
Properties.Settings.Default.UpdateSettings = false;
Properties.Settings.Default.Save();
Directory.Delete(VersionDirectoryfilePath, true);
}
}
这个方法在这里调用:
public MainForm()
{
InitializeComponent();
ApplicationUpdate();
GetSettingsValues();
}
一切正常,所以在成功升级
之后,用户设置被转移到新程序版本的user.config
,以前的程序版本目录和user.config
文件被删除。
我只需要记住在每个版本更新编码中更改 const string DeleteThisVersionDirectory
。
关于c# - 升级后删除以前版本的用户设置配置文件和目录 C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51138693/
我知道如何通过iPhone开发创建sqlite数据库、向其中插入数据、删除行等,但我试图以编程方式删除整个数据库本身,但没有得到任何帮助。请有人指导我如何通过代码从设备中删除/删除整个 sqlite
请帮助指导如何在 Teradata 中删除数据库。 当我运行命令DROP DATABASE database_name时,我收到错误消息: *** Failure 3552 Cannot DROP d
Azure 警报规则的删除命令似乎不起作用,尝试了下面的方法,它返回状态为无内容,并且警报未被删除 使用的命令Remove-AzAlertRule -ResourceGroup "RGName"-Na
我在 flex 搜索中为大约50000个视频建立了索引,但是当它达到52000左右时,所有数据都被删除。嗯,这对我来说真的很奇怪,我没有为ES设置任何Heap大小或最小或最大大小的内存大小,因此它们没
我正在处理的问题是表单错误“输入由字母、数字、下划线或连字符组成的有效‘slug’。” 以下是我的表单字段验证: def clean_slug(self): slug = self.c
阅读文档,我希望 $("#wrap2").remove(".error") 从 中删除所有 .error 元素#wrap2。然而看看这个 JSFiddle: http://jsfiddle.net/h
嗨,我第一次尝试发现 laravel 我从 laravel 4.2 开始,我刚刚创建了一个新项目,但我误以为我写了这样的命令行 composer create-project laravel/lara
我已经在网上搜索了很长一段时间,但我找不到如何完全删除 apache 2.4 。 使用: Windows 7 c:\apache24\ 我已经尝试了所有命令,但没有任何效果。 httpd -k shu
可能是一个简单的答案,所以提前道歉(最少的编码经验)。 我正在尝试从任何列中删除具有特定字符串(经济 7)的任何行,并且一直在尝试离开此线程: How to drop rows from pandas
有几种方法可以删除/移除 vector 中的项目。 我有一个指针 vector ,我需要在类的析构函数中删除所有指针。 什么是最有效/最快甚至最安全的方式? // 1º std::for_each(v
我安装了一个 VNC 服务器并在某处阅读了我必须安装 xinetd 的信息。稍后我决定删除 VNC 服务器,所以我也删除了 xinetd。似乎 xinetd 删除了一些与 plesk 相关的文件,如果
我制作了一个从我们的服务器下载视频的应用。问题是: 当我取消下载时,我打电话: myAsyncTask.cancel(true) 我注意到,myAsyncTask 并没有在调用取消时停止...我的 P
是否可以在使用DELETE_MODEL删除模型之前检查模型是否存在我试图避免在尝试删除尚未创建的模型时收到错误消息。基本上我正在寻找对应的: DROP TABLE IF EXISTS 但对于模型。 最
我已经有了这个代码: 但它仍然会生成一个表行条目。 我想做的是,当输入的数量为0时,表行将被删除。请耐心等待,因为我是 php 和 mySQL 编码新手。 最佳答案 您忘记执行查询。应该是 $que
在 SharePoint 中,如果您删除/修改重复日历条目的单次出现,则不会真正删除/修改任何内容 - 相反,会创建一个新条目,告诉 SP 对于特定日期,该事件不存在或具有新参数. 因此,这可以通过删
在 routes.php 中我有以下路由: Route::post('dropzone', ['as' => 'dropzone.upload', 'uses' => 'AdminPhotoContr
在我的应用程序中,我正在尝试删除产品。当我第一次删除产品时,它会成功并且 URL 更改为/remove_category/15。我正在渲染到同一页面。现在,当我尝试删除另一个产品时,网址更改为/rem
这个问题被问了很多次,但给出的答案都是 GNU sed 特定的。 sed -i '' "/${FIND}/,+2d""$FILE" 给出“预期的上下文地址”错误。 有人可以给我一个例子,说明如何使用
在使用 V3 API 时,我找不到任何方法来删除和清理 Google map 。 我已经在 AJAX 站点中运行它,所以我想完全关闭它而无需重新加载页面。 我希望有一个 .unload() 或 .de
是否可以创建一个 Azure SQL 数据库用户来执行以下操作: 针对所有表和 View 进行 SELECT 创建/更改/删除 View 但用户不应该不拥有以下权限: 针对任何表或 View 插入/更
我是一名优秀的程序员,十分优秀!