I was happily building my project when up popped this message:
Task failed because “sgen.exe” was not found, or the correct Microsoft Windows SDK is not installed. The task is looking for “sgen.exe” in the “bin” subdirectory beneath the location specified in the InstallationFolder value of the registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v6.0A. You may be able to solve the problem by doing one of the following: 1) Install the Microsoft Windows SDK for Windows Server 2008 and .NET Framework 3.5. 2) Install Visual Studio 2008. 3) Manually set the above registry key to the correct location. 4) Pass the correct location into the “ToolPath” parameter of the task.
I knew why I got it. Earlier in the day, I Had moved the files from the C:\Program Files\Microsoft SDKs\Windows folder to my D: drive to get rid of some pesky “you’re running out of space” messages.
So I opened RegEdit and changed the “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v6.0A” key to the right path and then rebuilt.
The solution was easy. I just closed Visual Studio 2008 and reopened it, and my next rebuild worked.