Pre-Build
UpdateAssemblyInfo
echo *** Build Resource file
"$(ProjectDir)dataresou rcesResgen.exe""$(ProjectDir)dataresourcesStringResources.zh-cn.txt""$(ProjectDir)dataresourcesStringResources.zh-cn.resources"
echo *** Build Resource file
"$(ProjectDir)dataresourcesResgen.exe""$(ProjectDir)dataresourcesStringResources.zh-cn.txt""$(ProjectDir)dataresourcesStringResources.cn-gb.resources"
"$(ProjectDir)dataresourcesResgen.exe""$(ProjectDir)dataresourcesStringResources.en.txt""$(ProjectDir)dataresourcesStringResources.en.resources"
Post-Build
echo *** Create solution directories
if not exist"$(SolutionDir)SunTechGUI"mkdir "$(SolutionDir)SunTechGUI"
echo *** Create addin directories
if not exist"$(SolutionDir)SunTechGUIAddins"mkdir "$(SolutionDir)SunTechGUIAddins"
echo *** Create data directories
if not exist"$(SolutionDir)SunTechGUIdata"mkdir "$(SolutionDir)SunTechGUIdata"
echo *** Create Settings directories
if not exist"$(SolutionDir)SunTechGUISettings"mkdir "$(SolutionDir)SunTechGUISettings"
echo *** Copy all compiled dll
xcopy "$(TargetDir)$(TargetName).exe""$(SolutionDir)SunTechGUI" /R /Y /Q /D
echo *** Copy all debug pdb files
xcopy "$(TargetDir)$(TargetName).pdb""$(SolutionDir)SunTechGUI" /R /Y /Q /D
echo *** Copy configuration add in file
xcopy "$(ProjectDir)Conf*.addin""$(SolutionDir)SunTechGUIAddins" /R /Y /Q /D
echo *** Copy data folder
xcopy "$(ProjectDir)data""$(SolutionDir)SunTechGUIdata" /E /Q /D /R /Y
echo *** Copy Setting folder
xcopy "$(ProjectDir)Settings""$(SolutionDir)SunTechGUISettings" /E /Q /D /R /Y
class UpdateAssemblyInfo
{
const string templateFile = "GlobalAssemblyInfo.template";
const string globalAssemblyInfo = "GlobalAssemblyInfo.cs";
const string configTemplateFile ="SunTech.MES.Framework.StartUp/app.template.config";
const string configFile ="SunTech.MES.Framework.StartUp/SunTech.MES.Framework.StartUp.exe.config";
const string configFile2 ="SunTech.MES.Framework.Smfa/SunTech.MES.Framework.Smfa.dll.config";
const string subversionLibraryDir =@"CommonLibrary/SunTech.MES.CommonLibrary.Client/ReferenceDlls";
static int Main(string[] args)
{
try
{
string exeDir =Path.GetDirectoryName(typeof(UpdateAssemblyInfo).Assembly.Location);
bool createdNew;
using (Mutex mutex = new Mutex(true,"SunTechMESFrameworkUpdateAssemblyInfo" + exeDir.GetHashCode(), outcreatedNew))
{
if (!createdNew)
{
// multiple calls in parallel?
// it's sufficient to let one call run, so just wait for the othercall to finish
try
{
mutex.WaitOne(10000, true);
}
catch (AbandonedMutexException)
{
}
return 0;
}
if (!File.Exists(@"SunTech-Power MES UserGUI.sln"))
{
string mainDir = Path.GetFullPath(Path.Combine(exeDir,"../"));
if (File.Exists(mainDir + @"\SunTech-Power MESUserGUI.sln"))
{
Directory.SetCurrentDirectory(mainDir);
}
}
if (!File.Exists(@"SunTech-Power MES UserGUI.sln"))
{
Console.WriteLine("Working directory must be SunTech-Power MESSolution\SunTech.MES.UserGUI!");
return 2;
}
FileCopy(Path.Combine(subversionLibraryDir, "SharpSvn.dll"),
Path.Combine(exeDir, "SharpSvn.dll"));
RetrieveRevisionNumber();
string versionNumber = GetMajorVersion() + "." +revisionNumber;
UpdateStartup();
//UpdateRedirectionConfig(versionNumber);
return 0;
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
return 3;
}
}
static void FileCopy(string source, string target)
{
if (File.Exists(target))
{
// don't copy file if it is up-to-date: repeatedly copying a 3 MBfile slows down the build
if (File.GetLastWriteTimeUtc(source) ==File.GetLastWriteTimeUtc(target))
return;
}
File.Copy(source, target, true);
}
static void UpdateStartup()
{
string content;
using (StreamReader r = new StreamReader(templateFile))
{
content = r.ReadToEnd();
}
content = content.Replace("-INSERTREVISION-",revisionNumber);
if (File.Exists(globalAssemblyInfo))
{
using (StreamReader r = new StreamReader(globalAssemblyInfo))
{
if (r.ReadToEnd() == content)
{
// nothing changed, do not overwrite file to preventrecompilation
// every time.
return;
}
}
}
using (StreamWriter w = new StreamWriter(globalAssemblyInfo, false,Encoding.UTF8))
{
w.Write(content);
}
}
static void UpdateRedirectionConfig(string fullVersionNumber)
{
string content;
using (StreamReader r = new StreamReader(configTemplateFile))
{
content = r.ReadToEnd();
}
content = content.Replace("$INSERTVERSION$",fullVersionNumber);
if (File.Exists(configFile) &&File.Exists(configFile2))
{
using (StreamReader r = new StreamReader(configFile))
{
if (r.ReadToEnd() == content)
{
// nothing changed, do not overwrite file to preventrecompilation
// every time.
return;
}
}
}
using (StreamWriter w = new StreamWriter(configFile, false,Encoding.UTF8))
{
w.Write(content);
}
using (StreamWriter w = new StreamWriter(configFile2, false,Encoding.UTF8))
{
w.Write(content);
}
}
static string GetMajorVersion()
{
string version = "?";
// Get main version from startup
using (StreamReader r = new StreamReader(templateFile))
{
string line;
while ((line = r.ReadLine()) != null)
{
string search = "string Major="";
int pos = line.IndexOf(search);
if (pos >= 0)
{
int e = line.IndexOf('"', pos + search.Length + 1);
version = line.Substring(pos + search.Length, e - pos -search.Length);
}
search = "string Minor = "";
pos = line.IndexOf(search);
if (pos >= 0)
{
int e = line.IndexOf('"', pos + search.Length + 1);
version = version + "." + line.Substring(pos + search.Length, e -pos - search.Length);
}
search = "string Build = "";
pos = line.IndexOf(search);
if (pos >= 0)
{
int e = line.IndexOf('"', pos + search.Length + 1);
version = version + "." + line.Substring(pos + search.Length, e -pos - search.Length);
}
}
}
return version;
}
static void SetVersionInfo(string fileName, Regex regex, stringreplacement)
{
string content;
using (StreamReader inFile = new StreamReader(fileName))
{
content = inFile.ReadToEnd();
}
string newContent = regex.Replace(content, replacement);
if (newContent == content)
return;
using (StreamWriter outFile = new StreamWriter(fileName, false,Encoding.UTF8))
{
outFile.Write(newContent);
}
}
#region Retrieve Revision Number
static string revisionNumber = "0";
static string ReadRevisionFromFile()
{
try
{
using (StreamReader reader = newStreamReader(@"..REVISION"))
{
return reader.ReadLine();
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.WriteLine();
Console.WriteLine("The revision number of the SharpDevelop versionbeing compiled could not be retrieved.");
Console.WriteLine();
Console.WriteLine("Build continues with revision number'0'...");
try
{
Process[] p = Process.GetProcessesByName("msbuild");
if (p != null && p.Length> 0)
{
System.Threading.Thread.Sleep(3000);
}
}
catch { }
return "0";
}
}
static void RetrieveRevisionNumber()
{
string oldWorkingDir = Environment.CurrentDirectory;
//string oldWorkingDir = @"E: 1 Project 1 MESFrameworkSunTech-Power MES Solution";
try
{
Environment.CurrentDirectory =Path.Combine(Environment.CurrentDirectory,subversionLibraryDir);
//Environment.CurrentDirectory = Path.Combine(@"E: 1 Project 1MES FrameworkSunTech-Power MESSolutionSunTech.MES.UserGUISunTechGUI",@"..CommonLibrarySunTech.MES.CommonLibrary.ClientReferenceDlls");
using (SvnClient svnClient = new SvnClient())
{
svnClient.Info(oldWorkingDir,
(sender, info) => {
revisionNumber =info.Revision.ToString(CultureInfo.InvariantCulture);
});
}
}
catch (Exception e)
{
Console.WriteLine("Reading revision number with SharpSvn failed: "+ e.ToString());
}
finally
{
Environment.CurrentDirectory = oldWorkingDir;
}
if (revisionNumber == null || revisionNumber.Length == 0 ||revisionNumber == "0")
{
revisionNumber = ReadRevisionFromFile();
}
if (revisionNumber == null || revisionNumber.Length == 0 ||revisionNumber == "0")
{
throw new ApplicationException("Error reading revisionnumber");
}
}
#endregion
}
http://www.shehui001.com/htm/200988/122.htm