Task failed because "sgen.exe" was not found
Asked Answered
P

7

6

I am getting the following error when attempting to build my project in Visual Studio 2008 Professional Edition:

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 tried downloading Microsoft Windows SDK for Windows Server 2008 and .NET Framework 3.5, and still get the error. I also tried downloading the Windows 7 SDK and .NET Framework 3.5 and still same result.

I also tried to manually editing the registry to change the InstallationFolder and I tried repairing the Visual Studio install.

The project was originally created on Windows XP and I am trying to compile on a reformatted machine running Windows 7 Enterprise.

Puree answered 19/8, 2009 at 19:1 Comment(0)
P
1

The problem appears to be caused by Visual Studio 2008 when using Web References. I ended up deleting the Web References and just used Service References.

I found a blog post about this posted here and here.

Puree answered 1/9, 2009 at 14:50 Comment(0)
C
8

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

See the explanation here:

Champlin answered 1/9, 2009 at 20:20 Comment(0)
C
3

This worked for me on Win 7 / VS.NET 2008:

The solution is: Download the Windows SDK and install .Net Development Tools (it says 2008 Server but I did this on XP SP3): http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=e6e1c3df-a74f-4207-8586-711ebe331cdc

Found it here, a post which includes a helpful screenshot of the minimal install of the SDK needed to fix this.

Champlin answered 24/11, 2009 at 22:46 Comment(0)
Q
3

In Visual Studio open the project setting property then select the Build tab on the left hand side. Select the All Configurations from the Configuration drop down list. Then go down to the near the end of the panel and select Off from the drop down Generate Serialization assembly.

http://support.microsoft.com/kb/955715

Quelpart answered 21/5, 2013 at 20:19 Comment(0)
P
1

The problem appears to be caused by Visual Studio 2008 when using Web References. I ended up deleting the Web References and just used Service References.

I found a blog post about this posted here and here.

Puree answered 1/9, 2009 at 14:50 Comment(0)
H
0

On Win Server 2008 and fresh install of VS 2008, with a project originally created in VS2003 with a Web Reference, a comment on the page Todd Price linked to worked for me. In the project properties, under build, change configuration to 'All Configurations' and change 'Generate serialization assembly' to Off.

Hsiuhsu answered 7/7, 2010 at 4:28 Comment(0)
N
0

In many cases you will find that C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\ is empty. in this case you either have to install Visual Studio or SDK 2.0

Insted of the above time taking process you can just download sgen.exe from this link and paste it in “C:\WINDOWS\Microsoft.NET\Framework\v3.5\” location.

This worked great for me!! Hope this helps

Nannie answered 7/5, 2013 at 18:25 Comment(0)
U
0

This issue is quite "oldish", but it still seems to lurk in the inner workings of Microsoft Visual Studio / .net SDK

I installed Visual Studio 2020, Windows SDK and .net SDK just now. To try it and see if everything works as expected I chose the sources of KeePass2 , a password storage app.

When trying to compile it it would throw an error at me:

1>------ Erstellen gestartet: Projekt: KeePass, Konfiguration: Debug|AnyCPU ------ 1>C:\Users\First Last\Downloads\KeePass-2.54-Source\KeePassLib\Utility\XmlUtilEx.cs(62,4,62,19): warning CS0618: "XmlReaderSettings.ProhibitDtd" ist veraltet: "Use XmlReaderSettings.DtdProcessing property instead." 1>  KeePass -> C:\Users\First Last\Downloads\KeePass-2.54-Source\Build\KeePass\Debug\KeePass.exe 1>  Der Befehl ""C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\sgen.exe"" ist entweder falsch geschrieben oder 1>  konnte nicht gefunden werden.
========== Erstellen: 0 erfolgreich, 1 Fehler, 0 aktuell, 0 übersprungen ========== Erstellen fehlgeschlagen.

Checking C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin I found it to contain two subdirectories, namely NETFX 4.8 Tools and NETFX 4.8.1 Tools, which both in turn contain a copy of sgen.exe. Otherwise C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin was empty.

While researching for the possible reason and remedy I came across this post as well as https://learn.microsoft.com/en-us/dotnet/standard/serialization/xml-serializer-generator-tool-sgen-exe

The advice given there under Tip: did not help me any.

What I finally did, was simply copying sgen.exe into the location C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin, as was pointed out in this posting.

While this got me going, I still think there must be something behind the curtain, that leads to looking in the wrong place.

Unwitnessed answered 14/8, 2023 at 21:56 Comment(1)
This issue did leave me dissatisfied completely, as I feel extremely insecure when things need kludges to work properly. While trying this an that and digging through visual studio as well as google offerings, I came across "https://mcmap.net/q/655377/-sgen-exe-fails-during-build" which addresses another sgen.exe related issue, but made me look at the project files with a text editor. Finally there was the culprit as the final entry in the project clause calls for sgen.exe with absolute path. Correcting that to the true location of sgen.exe solved the issue finally.Unwitnessed

© 2022 - 2024 — McMap. All rights reserved.