2016-07-30 41 views
0

我使用Windows 10windres:文件名,目錄名或卷標語法不正確

我試圖編譯使用MinGW的C#中的C++文件(MinGW的文件夾,在項目目錄),但它不會編譯資源腳本(使用windres)。

每當我在cmd中使用windres時,它會顯示:「C:/Users/username/AppData/Local/Temp/my.rc:1:無法識別的轉義序列」。 但仍然有效。 但是,當我通過c#運行完全相同的命令(通過創建一個進程)它根本不起作用,並說:「文件名,目錄名稱或卷標語法不正確。」

我的代碼:

String tempDir = Path.GetTempPath(); 
String file = tempDir + "my.rc"; 

using (StreamWriter writer = new StreamWriter(file, false, Encoding.ASCII)) 
{ 
    if (!textIcon.Text.Equals("")) 
     await writer.WriteLineAsync("25 ICON \"" + textIcon.Text + "\""); 
    if (checkAdmin.Checked) 
    { 
     String manifest = tempDir + @"\manifest.xml"; 
     createManifest(manifest); 
     await writer.WriteLineAsync("55 24 \"" + manifest + "\""); 
    } 
} 

String args2 = "/c \"" + Path.Combine(gccLocation, "windres.exe") + "\" -o \"" + Path.Combine(tempDir, "my.o").Replace("\\", "/") + "\" \"" + file.Replace("\\", "/") + "\""; 

//Debug 
//args2 = "/k echo " + args2; 

ProcessStartInfo psi2 = new ProcessStartInfo(); 
psi2.FileName = "CMD.exe"; 
psi2.Arguments = args2; 
psi2.UseShellExecute = false; 
psi2.CreateNoWindow = true; 

//Debug 
//psi2.CreateNoWindow = false; 

Process windres = Process.Start(psi2); 
windres.WaitForExit(); 

if(windres.ExitCode != 0) 
{ 
    MessageBox.Show("Error: Could not create resource file (" + windres.ExitCode + ")"); 
} 
+0

其傳遞到CMD的參數有: /C 「的MinGW \ BIN \ windres.exe」 -o 「C:/Users/easyc/AppData/Local/Temp/my.o」,「C:/ Users/easyc/AppData/Local/Temp/my.rc「 – Yaron

+0

只能在設置ProcessStartInfo.WorkingDirectory時才能一致地工作,以便它可以可靠地找到MinGW子目錄。始終支持完整路徑名稱,c:\ foo \ bar \ baz.ext –

+0

我在此位代碼中添加了: if(!File.Exists(gccLocation + @「windres.exe」)) MessageBox.Show(「 windres不存在「); else MessageBox.Show(「windres exists。」); 和messagebox說「windres存在」。 – Yaron

回答

0

結束了使用一個批處理文件來運行該命令。

   String args2 = "windres.exe -i \"" + Path.GetFullPath(file) + "\" -o \"" + Path.Combine(tempDir, "my.o") + "\"" ; 

       using (StreamWriter writer = new StreamWriter(tempDir + @"\my.bat", false, Encoding.ASCII)) 
       { 
        await writer.WriteLineAsync("@echo off"); 
        await writer.WriteLineAsync("cd " + Path.GetFullPath(gccLocation)); 
        await writer.WriteLineAsync(args2); 
       } 

       //Debug 
       //args2 = "/k echo " + args2; 

       ProcessStartInfo psi2 = new ProcessStartInfo(); 
       psi2.FileName = tempDir + @"\my.bat"; 
       psi2.UseShellExecute = false; 
       psi2.CreateNoWindow = true; 

       //Debug 
       //psi2.CreateNoWindow = false; 

       Process windres = Process.Start(psi2); 
       windres.WaitForExit(); 
相關問題