내가 생각한 접근 방식은 내가 느끼는 해킹 방법이지만 너무 많은 접근 방식이 실패했습니다. 그리고 나는 일들을 계속해야합니다 :-(
새 버전이 실행될 때 이전 버전의 user.config를 복사했습니다.
먼저이 질문의 많은 변형이 권장하는 것처럼 업그레이드가 필요한지 여부를 결정하십시오. 다음
System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
Version version = assembly.GetName().Version;
if (version.ToString() != Properties.Settings.Default.ApplicationVersion)
{
copyLastUserConfig(version);
}
는 PreviousSettingsDir를 얻을 중간에 마지막 user.config ....이 질문에 (
How do you upgrade Settings.settings when the stored data type changes?)에 그의 대답에
Allon Guralnek에
private static void copyLastUserConfig(Version currentVersion)
{
try
{
string userConfigFileName = "user.config";
// Expected location of the current user config
DirectoryInfo currentVersionConfigFileDir = new FileInfo(ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal).FilePath).Directory;
if (currentVersionConfigFileDir == null)
{
return;
}
// Location of the previous user config
// grab the most recent folder from the list of user's settings folders, prior to the current version
var previousSettingsDir = (from dir in currentVersionConfigFileDir.Parent.GetDirectories()
let dirVer = new { Dir = dir, Ver = new Version(dir.Name) }
where dirVer.Ver < currentVersion
orderby dirVer.Ver descending
select dir).FirstOrDefault();
if (previousSettingsDir == null)
{
// none found, nothing to do - first time app has run, let it build a new one
return;
}
string previousVersionConfigFile = string.Concat(previousSettingsDir.FullName, @"\", userConfigFileName);
string currentVersionConfigFile = string.Concat(currentVersionConfigFileDir.FullName, @"\", userConfigFileName);
if (!currentVersionConfigFileDir.Exists)
{
Directory.CreateDirectory(currentVersionConfigFileDir.FullName);
}
File.Copy(previousVersionConfigFile, currentVersionConfigFile, true);
}
catch (Exception ex)
{
HandleError("An error occurred while trying to upgrade your user specific settings for the new version. The program will continue to run, however user preferences such as screen sizes, locations etc will need to be reset.", ex);
}
}
감사 Linq에 대한 복사합니다.
XML 파일 일뿐입니다. –
예 제레미 Xml이고, 오늘 아침에 시작한 트랙입니다. 그것은 Xml 파일이지만 새 버전의 응용 프로그램마다 사용자 프로필 내의 새 폴더에 새 Xml 파일이 만들어집니다. 현재, 나는 오래된 XML 파일을 찾고 모든 관련 설정 객체를 인스턴스화하기 위해 userSettings 노드를 읽는 중이다. 그것은 "해커"를 느낀다. 그리고 나는 더 좋은 길이 있는지 궁금하게 생각하고있다. (내가이 트랙을 시작하지 않았다는 것을 질문했을 때). 더 나은 것이 제시되지 않으면 결과를 게시 할 것입니다. –
나는 이것이 http://stackoverflow.com/questions/534261/how-do-you-keep-user-config-settings-across-different-assembly-versions-in-net의 사본이라고 생각한다. 여기에 수락 된 대답보다 더 나은 대답). –