我的任务是升级内部企业 Web 应用程序。用户输入一些数据,然后 Web 应用程序编译自定义 winforms EXE(自解压器/安装程序类型的应用程序),然后网站将其作为下载提供。
我们最近了解到这个自定义编译的安装程序在 Windows 7 中显示兼容性错误/警告。经过一些研究,我了解到我需要提供指定与 Windows 7 兼容性的应用程序 list :
相关链接:
- Stackoverflow article detailing the Windows 7 compatibility error
- MSDN Article which details what is required in the Application Manifest
- Sample code which shows how to set the compiler options
这是我第一次体验自定义/动态编译的代码和应用程序 list 。
由于此应用程序是动态编译的(从单个代码文件和一些嵌入式资源),我不能只向我的项目添加 list 。所以我在编译时使用了编译器的“/win32manifest”编译选项来引用manifest文件。
这里是来自自定义“Archive Compiler”类的一些代码,它实际上执行编译:(我只添加了应用程序 list 部分)
public void CompileArchive(string archiveFilename, bool run1stItem, string iconFilename)
{
CodeDomProvider csc = new CSharpCodeProvider();
CompilerParameters cp = new CompilerParameters();
cp.GenerateExecutable = true;
cp.OutputAssembly = archiveFilename;
cp.CompilerOptions = "/target:winexe";
// Custom option to run a file after extraction
if (run1stItem) {
cp.CompilerOptions += " /define:RUN_1ST_ITEM";
}
if (!string.IsNullOrEmpty(iconFilename)) {
cp.CompilerOptions += " /win32icon:" + iconFilename;
}
cp.ReferencedAssemblies.Add("System.dll");
cp.ReferencedAssemblies.Add("System.Windows.Forms.dll");
// Add application manifest to specify operating system compatibility (to fix compatibility warning in Windows 7)
string AppManifestPath = Path.Combine( System.Web.HttpContext.Current.Server.MapPath( "~/Content/" ), "CustomInstaller.exe.manifest" );
if ( File.Exists( AppManifestPath ) ) {
cp.CompilerOptions += string.Format( " /win32manifest: \"{0}\"", AppManifestPath );
}
// Add compressed files as resource
cp.EmbeddedResources.AddRange(filenames.ToArray());
// Compile standalone executable with input files embedded as resource
CompilerResults cr = csc.CompileAssemblyFromFile(cp, sourceCodeFilePath);
// yell if compilation error
if (cr.Errors.Count > 0) {
string msg = "Errors building " + cr.PathToAssembly;
foreach (CompilerError ce in cr.Errors) { msg += Environment.NewLine + ce.ToString(); }
throw new ApplicationException(msg);
}
}
但是,当我编译时,我不断遇到此错误:
Errors building D:\Projects\MySolution\WebAppName\App_Data\MyUsername\CustomInstaller.exe error CS2007: Unrecognized option: '/win32manifest:'
除了声明此参数存在且有效的文章之外,我无法找到与此相关的信息。该 Web 应用程序位于 Visual Studio 2010 中,并在 Framework 2.0 上运行。动态编译的应用程序也引用 .net 2.0(使用反编译器验证)。我不确定调用什么 EXE 来执行编译,或者我还可以检查什么来解决此问题。任何帮助将不胜感激。
最佳答案
可能需要删除此行中 /win32manifest:
和 \"{0}\"
之间的空格 cp.CompilerOptions += string.Format( "/win32manifest:\"{0}\"", AppManifestPath );
没有空格,它工作正常,当我添加空格时,如您的代码中所示,出现错误:
Errors building C:\Projects\Services\Services.WebUI\Binaries\install\temp\codedom.exe
error CS2005: Missing file specification for '/win32manifest:' option
warning CS2008: No source files specified
关于c# - 无法在我的动态编译的 C# 应用程序中包含 list ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11398466/