7

I am trying to build and deploy a .NET 4 project using MSBuild Web Deploy and TeamCity, I got this working fine (eventually) with an instance of TeamCity running on my local development machine, however when I tried to set up a fresh TeamCity instance with the same settings I got the following error:

\Microsoft.Common.targets(2249, 9): error MSB3086: 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'm running Windows Server 2008, and have .NET 4 installed, including (I believe) MSBuild 4. I've also installed Windows SDK 7.1 as other threads suggested this may be the problem, but still no luck. Any ideas or advice would be appreciated.

Thanks

sll
  • 61,540
  • 22
  • 104
  • 156
Ben
  • 1,767
  • 16
  • 32

4 Answers4

7

I had the same problem with TeamCity. Here are my steps to resolve:

  1. Download Windows SDK for Windows 7.1. If your server/user does not allow Web access, the Web installer won't work, so I recommend the full package download. Be careful to download the correct version -- x86 [32-bit], x64 [64-bit], or Itanium.
  2. During installation, you only need to select one option: .NET Development -> Tools enter image description here
  3. Try the build again. I did not need to restart my agent for the build to work correctly.

If you accept the default paths for installation, sgen.exe will be found here:

C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\sgen.exe
kevinarpe
  • 20,319
  • 26
  • 127
  • 154
6

There is/was something wonky about the way the windows SDK 7.0A installs with verus without visual studio. There are pathing issues. Easy way out is to install Visual Studio on the build machine, but that feels wrong. Or at least it does to me. Another option is to set your builds not to create the serialization assemblies -- they don't matter in many cases. Note that if you skip release builds this happens by default.

Real fix is to properly point TeamCity at sgen.exe and then tell msbuild to use the right folder by using the right toolspath. See this question for a good explanation.

Community
  • 1
  • 1
Wyatt Barnett
  • 15,573
  • 3
  • 34
  • 53
  • Thanks for the response, I agree installing VS on a build server seems massively wrong, but It looks like I may have to. I followed the advice in http://stackoverflow.com/questions/2748974/how-to-set-sgen-toolpath-in-msbuild-to-target-3-5-framework/5701714#5701714 and set the SdkToolsPath registry key, but got the same error, and turned serialisation off, same error again. I the weird thing is it's still looking for 7.0A but i've set the current version to 7.1. I may just have to install VS :-( any other advice would be appreciated. – Ben Nov 16 '11 at 10:53
  • @RitchMelton : why? part of the point of a build server is to make sure I can build this without the help of thick development tools. – Wyatt Barnett Nov 16 '11 at 14:42
  • @Wyatt - I've never considered building without 'thick development tools' a goal of CI, but installing VS alleviates quite a few problems like the the OP's. The problem with putting it on the server is that it consumes a license and you really shouldn't have to do it that way. – Ritch Melton Nov 16 '11 at 14:51
  • @RitchMelton : exactly -- you shouldn't need the editor to build the artifacts. Moreover, you really should understand how to build it without the tools, depending on black magic is bad. – Wyatt Barnett Nov 16 '11 at 15:24
  • I really hate the idea of installing VS on a build server, but then again I've been messing around in the registry, installing SDKs, changing build configurations and trying to change default SDKs all of which I didn't like doing and didn't work, so I've installed VS, and it works ... it doesn't mean I like it though :p Thanks for all the help :-) – Ben Nov 16 '11 at 15:29
  • @wyatt - Good lord. Infer much? – Ritch Melton Nov 16 '11 at 15:45
4

I banged my head on this for a full 8 hours, gave up, and figured it out in 30 minutes the next morning. I have tried everything I could find on the interwebs. Here is how i figured it out. I already confirmed that i have sdk 7.1, 7.0 installed on my build agent. Ultimately it came back to registry settings.

First for MSBUILD Under "HKEY_LOCAL_MACHINE\SOFTWARE\MSBUILD\ToolsVersions\4.0". The Key SDK40toolsPath value is $(Registry:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0A\WinSDK-NetFx40Tools-x86@InstallationFolder) on my build agent.

Which references "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0A\WinSDK-NetFx40Tools-x86@InstallationFolder". However, on my build agent that registry didn't exist! So it was referencing NOTHING. I don't know how the 7.0A registry setting are supposed to get there?!

So, I exported the entire "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0A" registry from a working build agent to a file then copied and imported it to the broken agent. It finally works now. Hope this helps someone.

This is probably over kill but here is the exported registry file contents.

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0A]
"InstallationFolder"="C:\\Program Files\\Microsoft SDKs\\Windows\\v7.1\\"
"ProductVersion"="7.1.7600.0.30514"
"ProductName"="Microsoft Windows SDK for Windows 7 (7.1.7600.0.30514)"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0A\WinSDK-NetFx40Tools]
"ProductVersion"="7.1.7600.0.30514"
"ComponentName"="Windows SDK Tools for .NET Framework 4.0"
"InstallationFolder"="C:\\Program Files\\Microsoft SDKs\\Windows\\v7.1\\Bin\\NETFX 4.0 Tools\\"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0A\WinSDK-NetFx40Tools-x64]
"ProductVersion"="7.1.7600.0.30514"
"ComponentName"="Windows SDK Tools for .NET Framework 4.0 (x64)"
"InstallationFolder"="C:\\Program Files\\Microsoft SDKs\\Windows\\v7.1\\Bin\\NETFX 4.0         Tools\\x64\\"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0A\WinSDK-NetFx40Tools-x86]
"ProductVersion"="7.1.7600.0.30514"
"ComponentName"="Windows SDK Tools for .NET Framework 4.0"
"InstallationFolder"="C:\\Program Files\\Microsoft SDKs\\Windows\\v7.1\\Bin\\NETFX 4.0 Tools\\"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0A\WinSDKBuild]
"InstallationFolder"="C:\\Program Files\\Microsoft SDKs\\Windows\\v7.1\\"
"ProductVersion"="7.1.7600.0.30514"
"ComponentName"="Microsoft Windows SDK Headers and Libraries"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0A\WinSDKIntellisenseNFX]
"InstallationFolder"="C:\\Windows\\Microsoft.NET\\Framework\\"
"ProductVersion"="7.1.7600.0.30514"
"ComponentName"="Microsoft Windows SDK Intellisense for .Net"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0A\WinSDKIntellisenseRefAssys]
"InstallationFolder"="C:\\Program Files\\Reference Assemblies\\Microsoft\\"
"ProductVersion"="7.1.7600.0.30514"
"ComponentName"="Windows SDK Intellisense and Reference Assemblies"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0A\WinSDKInterop]
"InstallationFolder"="C:\\Program Files\\Microsoft SDKs\\Windows\\v7.1\\"
"ProductVersion"="7.1.7600.0.30514"
"ComponentName"="Microsoft Windows SDK NetFx Interop"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0A\WinSDKNetFx35Tools]
"InstallationFolder"="C:\\Program Files\\Microsoft SDKs\\Windows\\v7.1\\bin\\"
"ProductVersion"="7.1.7600.0.30514"
"ComponentName"="Microsoft Windows SDK NetFx 3.5 Tools"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0A\WinSDKNetFx35Tools\1033]
"SP"=dword:00000000

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0A\WinSDKNetFx35Tools-x64]
"InstallationFolder"="C:\\Program Files\\Microsoft SDKs\\Windows\\v7.1\\bin\\x64\\"
"ProductVersion"="7.1.7600.0.30514"
"ComponentName"="Microsoft Windows SDK NetFx 3.5 Tools (x64)"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0A\WinSDKSamples]
"InstallationFolder"="C:\\Program Files\\Microsoft SDKs\\Windows\\v7.1\\Samples\\"
"ProductVersion"="7.1.7600.0.30514"
"ComponentName"="Windows SDK Samples"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0A\WinSDKTools]
"InstallationFolder"="C:\\Program Files\\Microsoft SDKs\\Windows\\v7.1\\bin\\"
"ProductVersion"="7.1.7600.0.30514"
"ComponentName"="Windows SDK Common Utilities"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0A\WinSDKTools-x64]
"InstallationFolder"="C:\\Program Files\\Microsoft SDKs\\Windows\\v7.1\\bin\\x64\\"
"ProductVersion"="7.1.7600.0.30514"
"ComponentName"="Windows SDK Common Utilities (x64)"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0A\WinSDKWin32Tools]
"InstallationFolder"="C:\\Program Files\\Microsoft SDKs\\Windows\\v7.1\\bin\\"
"ProductVersion"="7.1.7600.0.30514"
"ComponentName"="Windows SDK Utilities for Win32 Development"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0A\WinSDKWin32Tools-x64]
"InstallationFolder"="C:\\Program Files\\Microsoft SDKs\\Windows\\v7.1\\bin\\x64\\"
"ProductVersion"="7.1.7600.0.30514"
"ComponentName"="Windows SDK Utilities for Win32 Development (x64)"}
Gary M
  • 41
  • 1
  • Thanks for sharing, I ended up installing VS, nasty but it worked. If I come against this again I will definitely try and follow your advice. – Ben Aug 16 '12 at 16:52
0

In my case, the issue arose when I added a Web Reference (C# 2.0) to my project. I was able to get around it by building the proxy manually.

wsdl.exe /out:d:\dev\MyProxy.cs /order https://blahblahblah?wsdl

...then just copying MyProxy.cs into my project, instead.

Facio Ratio
  • 3,373
  • 1
  • 16
  • 18