Home DotNet Task failed because sgen was not found
Author:

I have recently install Visual Studio 2005 along with Visual Studio 2003 and 2008. Then when I try to compile the application I get this error:

Error 161 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.

Well the first two choices is definately is not an option for me as it would take forever to install Visual Studio so I will try one of these below solutions:

Solution 1

Try to add the registry key v6.0A with the value "InstallationFolder". You need to add the key the following path:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v6.0A

Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v6.0A]
"InstallationFolder"="C:\\Program Files\\Microsoft Visual Studio 8\\SDK\\v2.0\\"

Now reboot your computer and your problem should be fix. If its till not fix then try solution 2.

Solution 2

Because when Visual Studio is compiling the application it will try to look for the file sgen.exe in C:\WINDOWS\Microsoft.NET\Framework\v3.5, which the folder does not contain the file sgen.exe, it will failed.

A simple solution is to copy the sgen.exe file into the folder v3.5 and the issue should go away. The sgen.exe file can be found in C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\

Here is a quick copy paste which you can put it into the DOS command window.

copy /y “C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\sgen.exe”  “C:\WINDOWS\Microsoft.NET\Framework\v3.5\”

Did you like this tip?

Let's hope this will help you. Happy Programming.



Comments (4)
  • Anonymous  - Thanks
    It worked. Thank you so much..
  • satish  - thanks - solutin 2 worked
    thanks a lot.
    solution 2 worked for me
  • whambam
    Thanks for the solution. Great!!
  • ssis  - Works!
    I'm using SSIS script component and solution 2 worked for me.
Write comment
Your Contact Details:
Comment:
Security
Please input the anti-spam code that you can read in the image.

"