如何使用自定义 msbuild 任务读取注册表值?
我正在创建一个 MSBuild 任务,它将读取注册表中的特定注册表项。如果我在控制台应用程序中编写同一行代码(见下文),它会返回预期结果,但当它在 MSBuild 任务中时,它不会返回任何内容。
Return Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSSQLServer\Setup\", "SQLPath", Nothing)
我希望上面的代码如果键/值对不存在则返回 Nothing
,如果存在则返回该值。当 MSBuild 任务执行时,我什么也没有得到。我是否需要将某些属性应用于 MSBuild 任务的执行函数来告诉它需要读取注册表?
编辑:
这是从 MSBuild 任务执行的内容:
Return Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\MSSQLServer\Setup\", "SQLPath", Nothing)
我相信这是由 注册表重定向器,位于运行 32 位 MSBuild 的 Vista x64 计算机上。有什么方法可以告诉自定义 MSBuild 任务(用 VB .Net 编写)在 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSSQLServer\Setup\ 中查找,然后仅当那里不存在任何内容时才在 中查找>HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\MSSQLServer\Setup\
?
谢谢你,
斯科特·布鲁
I'm creating an MSBuild task that will read the registry for a specific registry key. If I write the same line of code (see below) in a console application, it returns the expected result, but when it is within the MSBuild task, it returns nothing.
Return Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSSQLServer\Setup\", "SQLPath", Nothing)
I would expect the above code to return Nothing
if the key/value pair doesn't exist, and return the value if it does exist. I am getting Nothing
when the MSBuild task gets executed. Is there some attribute that I need to apply to the Execute function of the MSBuild task to tell it that it needs to read the registry?
EDIT:
Here is what is being executed from the MSBuild task:
Return Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\MSSQLServer\Setup\", "SQLPath", Nothing)
I beleive this to be caused by the Registry Redirector on my Vista x64 machine running MSBuild in 32bit. Is there any way that you can tell the custom MSBuild task (written in VB .Net) to look in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSSQLServer\Setup\
then only if nothing exists there then look in HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\MSSQLServer\Setup\
?
Thank you,
Scott Blue
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以直接从 MSBuild 读取注册表,无需自定义任务,如下所示:
例如,
您说您希望从自定义任务中执行此操作,因此这可能不适用,但我将其发布以防万一有帮助。
You can read the registry directly from MSBuild, without a custom task, like this:
E.g.,
You said that you're looking to do this from a custom task, so this may not apply, but I'm posting it in case it helps.
我们的 msbuild 脚本从 x86 Visual Studio 命令提示符运行。使用此语法时,它不会读取 64 位注册表。是否有不同的语法允许 x86 读取 64 位注册表?
Our msbuild script runs from an x86 Visual Studio Command Prompt. It does not read the 64 bit registry when using this syntax. It there a different syntax which would allow the x86 to read the 64 bit registry?
使用 VB 的 If() 三元函数怎么样?
假设您有一个
Output()
属性:那么您所要做的就是从
Execute()
方法调用它:How about using VB's If() ternary function?
Assuming you have an
Output()
property:Then all you have to do is calling it from the
Execute()
method: