c# 工程加入 win32 资源文件
来源:互联网 发布:网络时间同步服务器ip 编辑:程序博客网 时间:2024/05/22 01:13
这种事情就是一个字烦人,蛋疼,特别蛋疼。 搞了我一天。
方法有几种,都特别烦,一个是 build event , 一个是 msbuild
今天说 build event
1.在 Build Events 中 , Pre-build
输入:
copy $(ProjectDir)Time/norlib.Time.Holidays.xml "$(TargetDir)norlib.Time.Holidays.xml"set VCInclude=C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\atlmfc\includeset SDKInclude=C:\Program Files (x86)\Windows Kits\8.0\Include\umset SDKShared=C:\Program Files (x86)\Windows Kits\8.0\Include\sharedecho $(IntermediateOutputPath)set RCDIR=IF EXIST "C:\Program Files (x86)\Windows Kits\8.0\bin\x86\rc.exe" (set RCDIR="C:\Program Files (x86)\Windows Kits\8.0\bin\x86\rc.exe")echo (%RCDIR% /i "%VCInclude%" /i "%SDKInclude%" /r /fo "$(IntermediateOutputPath)\res1.res" "$(ProjectDir)Controls\OpenFileOrFolderDialog\res1.rc")if not defined RCDIR ( echo "Error! Unable to find rc.exe.") else (%RCDIR% /i "%VCInclude%" /i "%SDKInclude%" /i "%SDKShared%" /r /fo "$(ProjectDir)res1.res" "$(ProjectDir)Controls\OpenFileOrFolderDialog\res1.rc")if not defined RCDIR (Exit 1)
主要是从第二行开始看
首先要注意 c# 下面很多宏是失效的, 比如 $(VCInstallDir) , 还有写宏和 vc 是指向不一样的目录,比如他妈的: $(FrameworkSdkDir)
这个宏 $(FrameworkSdkDir) 在vc下 指向: C:\program files(x86)\windows kits\8.0\ 在里面bin\x86 我们可以找到rc.exe
但是在 c# 下指向:C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\
瞬间晕死, google了半天发现个帖子:
http://go4answers.webhost4life.com/Example/get-winsdk-configuration-tool-work-41266.aspx
他这么说的:
After some investigation and reflecting using Redgate Reflector, I found that the variable $(FrameworkSDKDir) will always resolve to the 6.0a installation if that SDK is installed and the target framework is 3.5. This is due to a possible bug in the .NET Type Microsoft.Build.Shared.FrameworkLocationHelper, in assembly Microsoft.Build.Utilities.v3.5, Version=3.5.0.0 that shipped with .NET Framework 3.5. The problem I see is in the property PathToDotNetFrameworkSdkV35 in this class. It first reads the registry value for SOFTWARE\Microsoft\Microsoft SDKs\Windows\v6.0A\InstallationFolder, while I believe it should actually first read SOFTWARE\Microsoft\Microsoft SDKs\Windows\CurrentInstallFolder. I worked around this problem by hacking the key SOFTWARE\Microsoft\Microsoft SDKs\Windows\v6.0A\InstallationFolder to point to 6.1. This enables me to use rc.exe from SDK 6.1, while it might affect other products that expects to retrieve the 6.0a installation folder from the registry.I have the following questions regarding the issues described above:Why would rc.exe install to different locations on two otherwise seemingly equivalent machines? Is the code that I refered to in Microsoft.Build.Shared.FrameworkLocationHelper affected by a bug? and if soIs there a work around / fix other that the method that I described?
反正要解决也挺麻烦的,后来如你所见我就在 build events 里面创建了一个 %Macro%
比如:
set VCInclude=C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\atlmfc\include
这里要注意了,你不能写 VCInclude =....... 这样Macro变成了 %VCInclude % .........还有就是不需要双引号。
这样编译成功后, 就有了一个 res 文件,我们千辛万苦就是为了得到这个res文件
然后 c# Project Property -> Application -> Resources -> Resource file (radio button): 输入res文件的绝对路径
这样就能加入了win32资源文件了
里面挺好玩的。
参考:
http://stackoverflow.com/questions/8057080/how-to-embed-a-resource-in-a-net-pe-executable
http://blogs.msdn.com/b/astebner/archive/2006/02/28/541036.aspx
以后还是要上MSBUILD
- c# 工程加入 win32 资源文件
- 使用C#工程里的资源文件
- C#读取Win32标准DLL文件中的字符串资源
- Win32程序资源文件
- 将zip文件加入资源
- 在资源文件中加入声音资源
- C#编译时出现不是win32有效的资源文件的解决方法
- 将文件加入 eclipse java工程
- 用资源文件做捆绑工具,(exe加入资源文件)
- Qt入门-加入资源文件
- Qt入门-加入资源文件
- framework中加入图片资源文件
- Win32窗体应用程序如何添加资源文件?
- VC6.0 环境下Win32 Application工程添加资源
- C#资源文件
- c#读取资源文件
- 转:C#资源文件
- c# winForm 资源文件
- 异或法求数据是否相同 并查集应用——————没搞懂【小米】
- 问题七十一:简单密码破解(acm)
- hql中的错误
- ubuntu vi设置行号、加亮语法字体等
- js面向对象编程-prototype
- c# 工程加入 win32 资源文件
- 算法的力量(李开复)
- 如何在Xcode平台上安装并创建新的cocos2d-x项目
- 使用ImageView时使用src参数设置显示内容时需要设置scaleType参数
- jsp中if判断和遍历集合
- android jsonreader
- 渐变色背景窗体
- JS操作JSON实例
- MySql 实现row_number时的问题