How to Fix error Task could not find "sgen.exe" using the SdkToolsPath for v7.0a in VS2010
by
Doug
Updated June 26, 2012
I installed the Windows SDK version 7.1, and then just copied and pasted the "sgen.exe" file to the missing file location under Windows SDK directory for v7.0a.
Another option that worked for me was to turn Generate serialization assembly to Off in my VS2010 projects Build settings.
UPDATE 12-16-2011: For those of you who are getting an "sgen.exe" error message when trying to building your project in Visual Studio that reads something like "Could not load file or assembly or one of its dependencies. Operation is not supported. SGEN". This is most likely due to a .dll in your solution that needs to be unblocked. To do this go to the bin folder, right-click on a .dll file -> then in the Properties window, you will have the option to click the "Unblock" button (if the .dll is causing a problem). Read more about this sgen .dll problem here. (END)
I recently started using Visual Studio 2010 Express to build web application projects with Windows 7 (x64 bit computer). When compiling the solution with the configuration set to Debug, I didn't have any problems. However, once I set the solution to build to Release, I got the following sgen.exe not found error:
Task could not find "sgen.exe" using the SdkToolsPath "C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\NETFX 4.0 Tools\" or the registry key
"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0A". Make sure the SdkToolsPath is set and the tool exists in the correct processor specific location under the SdkToolsPath and that the Microsoft Windows SDK is installed
I tried finding the "sgen.exe" application within the "Microsoft SDKs\Windows\v7.0a\bin\NETFX 4.0 Tools\" directory and could not find it, nor anywhere else on my computer. I also tried downloading the Windows SDK version 7.0, but that installed v7.0 (not v7.0a) and didn't solve the problem. My computer seemed to be missing a bunch of Windows SDK file information for the v7.0a version. Inevitably, after lots of head scratching here's what I did to fix the "sgen.exe" not found error in Visual Studio 2010:
- I downloaded and installed the latest SDK (as of this post) Windows SDK v7.1 for Windows 7.
- I then went to the following directory: C:\Program Files\Microsoft SDKs\Windows\v7.1\Setup and opened the WindowsSdkVer application, and in the Windows SDK Configuration Tool pop-up box, changed the Installed Windows SDK Versions drop down box to v7.1 and then clicked the Make Current button. I then got a message box that says "The Windows SDK Configuration Tool has successfully set Windows SDK version v7.1 as the current version for Visual Studio 2008" ( I have Visual Studio 2008 installed on my computer). Unfortunately, making this change did not stop the Release build "sgen.exe" not found errors from occurring in Visual Studio 2010.
- So what I did was copied the v7.1 sgen.exe application file located at C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\NETFX 4.0 Tools\sgen.exe and the pasted it in to the v7.0a directory at C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\NETFX 4.0 Tools\.
- Since my computer is running 64bit Windows 7, you'll notice that C:\Program Files for 64bit progam files and C:\Program Files (x86) is for 32bit files, but so far this difference wasn't an issue.
- After copying the v7.1 sgen.exe over to the v7.0a directory that was listed in the error message that I got above, I was able to successfully build my VS2010 website project in Release mode and successfully build the deployment package.
That's what did the trick for me, and got things to build successfully in Visual Studio 2010!
If that didn't work for you, then the one other thing that I tried that also worked for me was to change the Build settings for "Generate serialization assembly" to Off in my VS2010 project.
- Open your project in Visual Studio 2010, and then Right-click on your project file and select Package/Publish Settings.
- Then click on the Build tab and scroll down to the Output section.
- Change the Generate serialization assembly from "Auto" to "Off"
- Save your settings and try building your project.
By turning off the Generate serialization assembly, I was also successfully able to build my project without getting the "sgen.exe" not found error. However, you will need to investigate whether turning off Generate serialization assembly will affect other parts of your project (I'm not sure if it will or not).
So those were the two solutions that were able to get me past the "sgen.exe" not found error for the Windows SDK "v7.0a".