System variable for Microsoft SDKs - msbuild

Similar to the %WINDIR% system variable which we have for the Windows directory, do we have any system variable which points to the latest version of the Microsoft SDK folder, so that I can access the sn.exe in my Build script?

I am running MSBuild 4.0 and in my proj file ToolsVersion is set to 4.0. The variable SDK40ToolsPath points to where the .NET 4.0 tools are installed. SDK35ToolsPath points to where the .NET 3.5 tools are installed.
MSBuild reads these variables, base on the value of ToolsVersion, from the registry at: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSBuild\ToolsVersions\4.0.

Related

building x64 c# project with msbuild results in 32bit targets

I'm using Visual Studio 2010 to build a c# project that has both x86 and x64 targets. When I build using the IDE, I get the correct result of x64 and x86 targets.
When I use msbuild on the command line, I get everything built in x86, even though i specify x64 on the command line.
I didn't have this problem until I upgraded from .Net 4.0 to .Net 4.5.
With .Net 4.0 I was able to get my x64 targets even if I specified x86 on the command line.
I did a build in the .Net 4.0 environment and then another build in the .Net 4.5 environment and piped the output into log files. I noticed some differences in the log files but I think this is what is causing my issue:
In .Net 4.0 I see this line in the log file:
/reference:C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.CSharp\v4.0_4.0.0.0__b03f5f7f11d50a3a\Microsoft.CSharp.dll
In .Net 4.5 I see this line in the log file:
/r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\Microsoft.CSharp.dll"
Any ideas? It seams .Net 4.5 is using an x86 specific path.
This could happen if your solution's x64 configuration is configured to build project as AnyCPU. A new configuration option in .Net 4.5, Prefer 32 bit, makes executables with Prefer32bit flag to start up as 32-bit processes on 64 bit machine. Since Prefer32bit flag is default in MSBuild targets, you will see the behavior you describe, i.e. upgrading from .Net 4.0 to .Net 4.5 will have your AnyCPU project to switch from 64 bit to 32 bit.
To make project (not solution) built for x64, specify it on command line:
msbuild project.csproj /p:Platform=x64
Notice, the command line is for .csproj, not for .sln.
Alternatively, verify you solution configuration in Configuration Manger and make sure it gets built as x64.

Where is GACUTIL for .net Framework 4.0 in windows 7?

i've made an assembly in the .net framework that I intend to publish to the GAC but I can't find the gacutil utlity.
I've been googling a while and I've found a lot of suggestions, but nothing works:
Copy the assemby to %window%\assemby [DOES NOT WORK]
Copy the assemby to %window%\Microsoft.NET\assembly [DOES NOT
WORK]
C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin\gacutil.exe /i
"assembly" [returns an error: this assembly is built by a runtime newer
than the currently loaded runtime and cannot be loaded]
Does anyone have idea to solve this?
If you've got VS2010 installed, you ought to find a .NET 4.0 gacutil at
C:\Program Files\Microsoft SDKs\Windows\v7.0A\bin\NETFX 4.0 Tools
The 7.0A Windows SDK should have been installed alongside VS2010 - 6.0A will have been installed with VS2008, and hence won't have .NET 4.0 support.
VS 2012/13 Win 7 64 bit
gacutil.exe is located in
C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools
There is no Gacutil included in the .net 4.0 standard installation. They have moved the GAC too, from %Windir%\assembly to %Windir%\Microsoft.NET\Assembly.
They havent' even bothered adding a "special view" for the folder in Windows explorer, as they have for the .net 1.0/2.0 GAC.
Gacutil is part of the Windows SDK, so if you want to use it on your developement machine, just install the Windows SDK for your current platform. Then you will find it somewhere like this (depending on your SDK version):
C:\Program Files\Microsoft SDKs\Windows\v7.0A\bin\NETFX 4.0 Tools
There is a discussion on the new GAC here: .NET 4.0 has a new GAC, why?
If you want to install something in GAC on a production machine, you need to do it the "proper" way (gacutil was never meant as a tool for installing stuff on production servers, only as a development tool), with a Windows Installer, or with other tools. You can e.g. do it with PowerShell and the System.EnterpriseServices dll.
On a general note, and coming from several years of experience, I would personally strongly recommend against using GAC at all. Your application will always work if you deploy the DLL with each application in its bin folder as well. Yes, you will get multiple copies of the DLL on your server if you have e.g. multiple web apps on one server, but it's definitely worth the flexibility of being able to upgrade one application without breaking the others (by introducing an incompatible version of the shared DLL in the GAC).
There actually is now a GAC Utility for .NET 4.0. It is found in the Microsoft Windows 7 and .NET 4.0 SDK (the SDK supports multiple OSs -- not just Windows 7 -- so if you are using a later OS from Microsoft the odds are good that it's supported).
This is the SDK. You can download the ISO or do a Web install. Kind-of overkill to download the entire thing if all you want is the GAC Util; however, it does work.

Install dll into the gac + .net 4.0

I want to add some .net 4.0 dlls to the gac, I know that the new gac is C:\Windows\Microsoft.NET\assembly
I cannot use the gacutil because visual studio in not installed on the deployment machine, and i cannot simply drag/drop the dll to the folder as i usually do in the previous versions.
How can I install the dlls to the GAC.
It is part of Windows SDK and can be download separately at http://www.microsoft.com/downloads/en/details.aspx?FamilyID=6B6C21D2-2006-4AFA-9702-529FA782D63B. This installation will have gacutil.exe included. But first check it here: C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin you might have it installed
where is gacutil.exe?
UPDATE : Modified the link. Windows SDK for .Net 4.0
Using Microsoft Installer Package. You can get download of installer from
http://www.microsoft.com.
I am not confirmed but ideally Gacutil must be part of framework and you can find it out in .net framework folder

WIX: GenerateBootStrapper conditions?

I've built an installer with WIX and have packaged it with the .NET 4.0 framework using the GenerateBootstrapper task. Now .NET 4.0 cannot be installed on XP SP2, but it appears to have no precondition check for this so its installer fails halfway through.
I'd like to add my own check to make sure the OS that the entire package is being installed on is supported by the .NET 4.0 framework. Is there a way to embed an OS/Service Pack check in the bootstrapper when you use GenerateBootstrapper? If not, how else can I accomplish this?
You could add a condition to the bootstrapper package definition file so that the bootstrapper will check for the Windows version. The description file is located at
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bootstrapper\
Packages\DotNetFX40\Product.xml
on a 64-bit Windows system or at
C:\Program Files\Microsoft SDKs\Windows\v7.0A\Bootstrapper\
Packages\DotNetFX40\Product.xml
on a 32-bit Windows system. The package.xml already contains such a check, see the line
<!-- Block install on less than Windows XP SP2 -->
<FailIf Property="VersionNT" Compare="VersionLessThan"
Value="5.1.2" String="InvalidPlatformWinNT" />
I couldn't find the relevant documentation, but it looks as if the third number of the VersionNT value is the service pack level, so probably changing the condition to check for a value of "5.1.3" will do the job.

Where is the .NET Framework Global Assembly Cache?

I installed the VS2010 and .NET 4.0, then I compiled an assembly and ran the gacutil using the exe available on
%ProgramFiles%\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools
The output of the executable said the assembly was sucessfully installed on Global Assembly Cache. However, when I go to %WINDIR%\assembly folder I cannot find the assembly I installed using the .NET Framework 4.0 gacutil.
I've seen some posts saying the .NET Framework 4.0 has a separated GAC, but what I haven't found was where it is located.
May someone to help me to check where can I see the Global Assembly Cache of .NET Framework, as it used to work on previous version (%WINDIR%\assembly)?
Yes, there are two distinct GACs as from .NET 4.0
See here: .NET 4.0 has a new GAC, why?
As stated below, the new physical location is %windir%\Microsoft.NET\assembly\ (you can interogate it using the dir command at a command prompt if you're interested).
It's worth noting that applications running up to the 2.0 CLR will not even be able to see assemblies in the new GAC.
Try:
%windir%\Microsoft.NET\assembly\
Due to Common Language Runtime (CLR) changes, the contents of the Global Assembly Cache (GAC) is split between two directories:
%WINDIR%\assembly\
%WINDIR%\Microsoft.NET\assembly\
If you run the command gacutil -l from the directory of your project's .csproj file, you will get a printout of the contents of the GAC (the contents of both directories).