答案很簡單。它應該工作。但事實並非如此。
Visual Studio用於生成CAB文件的Microsoft工具CABWiz中顯然存在一個錯誤。在不同的子文件夾中使用具有相同名稱的文件時會遇到問題,例如在使用本地化時。
經過幾小時的努力修復,我終於得到了一個靈感來自the CodeProject guide的解決方案,正如Cornel在前面的答案中給出的那樣:您必須通過使用具有唯一性的資源文件來「破解」Visual Studio生成CAB的過程名稱,然後修改INF文件以指定在設備上進行部署的原始名稱。
爲了使自動化多一點,我做了被推出,項目生成後一點EXE:
FileInfo CurrentExeInfo = new FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location);
// Current Folder + bin\Debug
DirectoryInfo BinDebug = new DirectoryInfo(Path.Combine(CurrentExeInfo.Directory.FullName, @"bin\Debug"));
// Subfolders in \bin\Debug
Console.WriteLine(BinDebug.FullName);
string[] Dirs = Directory.GetDirectories(BinDebug.FullName, "*", SearchOption.TopDirectoryOnly);
// In each localization folder ...
foreach (string Dir in Dirs)
{
DirectoryInfo DirInfo = new DirectoryInfo(Dir);
// ... Resource files
string[] RFiles = Directory.GetFiles(Dir, "*.resources.dll");
foreach (string RFile in RFiles)
{
FileInfo RFileInfo = new FileInfo(RFile);
bool DoCopy = false;
// No underscore in resource name
if (!RFileInfo.Name.Contains("_") || RFileInfo.Name.IndexOf("_") == 0)
{
DoCopy = true;
}
// underscore in resource name
// --> Have to check if already a copy
else
{
// prefix removal
int PrefixIndex = RFileInfo.Name.IndexOf("_");
string TestFilename = RFileInfo.Name.Substring(PrefixIndex + 1);
if (!File.Exists(Path.Combine(Dir, TestFilename)))
{
// File without underscore does not exist, so must copy
DoCopy = true;
}
}
if (DoCopy)
{
// Copy file
string NewFileName = Path.Combine(Dir, DirInfo.Name.ToUpper() + "_" + RFileInfo.Name);
Console.WriteLine("Copying " + RFile + " -> " + NewFileName);
File.Copy(RFile, NewFileName, true);
}
}
}
再正常CAB代在此之後CAB補丁:
const string cabwizpath = @"C:\Program Files (x86)\Microsoft Visual Studio 9.0\SmartDevices\SDK\SDKTools\cabwiz.exe";
static void Main(string[] args)
{
if (args.Length == 0)
{
Console.WriteLine("Aborted: You must enter the inf file information");
Console.ReadLine();
return;
}
if (!File.Exists(args[0]))
{
Console.WriteLine("Aborted: I can not found the INF file!");
Console.ReadLine();
return;
}
// string to search
Regex R = new Regex("\"[A-Z]{2,3}_(.+)\\.resources\\.dll\",\"([A-Z]{2,3})_(.+)\\.resources\\.dll\"");
// File reading
string inffile = File.ReadAllText(args[0]);
// Format replace from
// "FR_ProjectName.resources.dll","FR_ProjectName.resources.dll"
// To
// "ProjectName.resources.dll","FR_ProjectName.resources.dll"
inffile = R.Replace(inffile, "\"$1.resources.dll\",\"$2_$3.resources.dll\"");
// Rewriting file
File.WriteAllText(args[0], inffile);
Console.WriteLine("INF file patched ...");
// Génération du CAB ...
Console.WriteLine("Generating correct CAB ... ");
System.Diagnostics.ProcessStartInfo proc = new System.Diagnostics.ProcessStartInfo("\"" + cabwizpath + "\"", "\"" + args[0] + "\"");
proc.ErrorDialog = true;
proc.UseShellExecute = false;
proc.RedirectStandardOutput = true;
Process CabWiz = Process.Start(proc);
Console.WriteLine("\""+cabwizpath + "\" \""+ args[0]+"\"");
CabWiz.WaitForExit();
Console.WriteLine("CAB file generated (" + CabWiz.ExitCode + ") !");
}
希望它有助於。
更多關於此鏈接:
您是否驗證了CAB文件的實際安裝本地化的資源集合? –
CF沒有「本地化」部分。您可能不會在CAB中部署本地化資源,或者將它們部署到錯誤的地方。 – ctacke