用C#写的转换程序(将高版本项目转变成低版本)
来源:互联网 发布:腾讯游戏平台 mac版 编辑:程序博客网 时间:2024/05/16 17:46
源码:
//可以在这个链接中下载 http://pan.baidu.com/s/1qWFN4CW//将在窗体中放一个按钮(btnOpen)一个按钮(btnConvert), 一个文本框(txtFolder), 一个打开文件夹的对话框(在工具箱上找到“对话框”)//本程序的作用是:将项目转成低版本的程序//主要是考虑到有的同学用的Visual Studio的低版本(如2010),不能打开VisualStudio2013的版本不方便using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.IO; namespace SolutionVersionConverter{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void btnOpen_Click(object sender, EventArgs e) { if (this.folderBrowserDialog1.ShowDialog() == DialogResult.OK) this.txtFolder.Text = this.folderBrowserDialog1.SelectedPath; } private void btnConvert_Click(object sender, EventArgs e) { ConvertInPath(new DirectoryInfo(this.txtFolder.Text.Trim())); MessageBox.Show("ok!"); } void ConvertInPath(DirectoryInfo path) { if(! path.Exists) return; foreach (FileInfo file in path.GetFiles()) { string filepath = file.FullName; if (filepath.ToLower().EndsWith(".sln")) ConvertSln(filepath); else if (filepath.ToLower().EndsWith(".csproj")) ConvertPrj(filepath); else if (filepath.ToLower().EndsWith(".config")) ConvertCfg(filepath); } foreach( DirectoryInfo subpath in path.GetDirectories() ) { ConvertInPath(subpath); } } void ConvertSln(string path) { StreamReader sr = new StreamReader(path, Encoding.UTF8); string content = sr.ReadToEnd(); sr.Close(); if (content.IndexOf("Microsoft Visual Studio Solution File, Format Version 12.00")>=0) { content = content.Replace("Microsoft Visual Studio Solution File, Format Version 12.00", "Microsoft Visual Studio Solution File, Format Version 11.00"); content = content.Replace("# Visual Studio 2013", "# Visual Studio 2010"); content = content.Replace("# Visual Studio 2012", "# Visual Studio 2010"); content = content.Replace("# Visual Studio Express 2013 for Windows Desktop", "# Visual Studio 2010"); content = content.Replace("# Visual Studio Express 2012 for Windows Desktop", "# Visual Studio 2010"); StreamWriter sw = new StreamWriter(path,false, Encoding.UTF8); sw.Write(content); sw.Close(); } } void ConvertPrj(string path) { StreamReader sr = new StreamReader(path, Encoding.UTF8); string content = sr.ReadToEnd(); sr.Close(); if (content.IndexOf("<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>")>=0) { content = content.Replace("<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>", "<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>"); content = content.Replace("<ProjectGuid>", "<ProductVersion>8.0.30703</ProductVersion><ProjectGuid>"); content = content.Replace("<SignManifests>true</SignManifests>", "<SignManifests>false</SignManifests>"); StreamWriter sw = new StreamWriter(path, false, Encoding.UTF8); sw.Write(content); sw.Close(); } } void ConvertCfg(string path) { StreamReader sr = new StreamReader(path, Encoding.UTF8); string content = sr.ReadToEnd(); sr.Close(); if (content.IndexOf("<supportedRuntime version=\"v4.0\" sku=\".NETFramework,Version=v4.5\" />")>=0) { content = content.Replace("<supportedRuntime version=\"v4.0\" sku=\".NETFramework,Version=v4.5\" />", "<supportedRuntime version=\"v4.0\" sku=\".NETFramework,Version=v4.0\" />"); StreamWriter sw = new StreamWriter(path, false, Encoding.UTF8); sw.Write(content); sw.Close(); } } }}
运行效果如下:
1 0
- 用C#写的转换程序(将高版本项目转变成低版本)
- 将低版本的项目转换到VS2010后“无法启动程序”的问题
- VS项目从高版本到低版本转换解决
- 低版本的ArcEngine项目升级到高版本的ArcEngine程序
- SQL2008 转 2000(高版本转换到低版本)
- android 项目 高版本 换成 低版本
- android 项目高版本换成低版本
- android 项目 高版本 换成 低版本
- 低版本vs导入高版本项目
- android 项目 高版本 换成 低版本
- oracle 高版本将数据导入低版本(乌托邦的村长)
- CAD版本转换高版本转低版本
- VS低版本打开高版本解决方案(如08打开10、12、13版本vs编译的项目)
- VS低版本打开高版本解决方案(如08打开10、12、13版本vs编译的项目)
- 如何将数据库由高版本降为低版本
- 如何将高版本的SQL Server数据库备份到低版本的SQL Server
- 如何将高版本的数据库还原到低版本服务器?
- 如何将高版本oracle的数据导入到低版本oracle数据库中
- MyEclipse设置自动提示
- Linux tcpdump命令详解
- 前几天用AnnotationSessionFactoryBean 注解方式代替*.hbm.xml时扫描映射实休文件后报错
- LeetCode 222. Count Complete Tree Nodes(完全二叉树节点数统计)
- poj 2195
- 用C#写的转换程序(将高版本项目转变成低版本)
- 错过了愚人节,还有清明节
- Java邮件发送
- js开发的45个人技巧
- 【算法】蛇形矩阵
- cocos开发环境配置
- 30.C语言结构体对齐访问
- PigPen:用Clojure写MapReduce Introducing PigPen: Map-Reduce for Clojure
- HDU 4292 最大流