Reference paths...

Topics: For MSBee Users
Aug 17, 2006 at 12:09 AM
migrated from power toy forums
originally posted by Alan J. McFarlane
------------------------------------------------------


I have a project (actually multiple) that references two third-party libraries (one being NUnit for instance). Under MSBee the compiler couldn't find the assemblies... In VS the paths appear absolute, but (eventually!) I discovered that the .csproj file simply has the assembly Full Name with no paths apparent at all.

So eventually (again! :-)) I found the Reference Paths tab in VS and added the two paths necessary.

So what's the best solution here?

Why is it like this? Why can't the compiler find the assemblies under MSBee? Why is VS showing an absolute path, where its not the case internally (apparently). I first thought it was that that the libraries were only in the v2 GAC. But that does not seem to be the case (one if the library is not in any GAC). (Is the GAC even separate per FX version?) Then I suspected the Registry "AssemblyFolders", but there doesn't seem to be separate locations for v1.1 vs v2.0 in my extant registry , but...

Any advice appreciated.

Oh, I should note that this aside I'm very happy with MSBee. :-)

Alan
Aug 17, 2006 at 12:09 AM
originally posted by Bertan Aygun - MSFT
------------------------------------------------------

Alan,

If you add a reference to an assembly that is not in GAC, you should have a hint path in your csproj file that points to the location of the assembly similar to below:

<Reference Include="Full AssemblyName">
<HintPath>Relative path to assembly</HintPath>
</Reference>

If HintPath is not there for the references you added, can you try adding it manually and see if it works with the reference path entries.

Thanks,

Bertan
Aug 17, 2006 at 12:10 AM
originally posted by Alan J. McFarlane
------------------------------------------------------

I went back and removed all the Reference Paths entries. I then removed all the third-party assembly references then re-added them. The second third-party library is not in either GAC, but it does appear in the .NET tab of the Add Reference dialog, and after all that there are still no HintPath elements in any of the csproj files.

The normal build completes fine. And the MSBee build fails... So my suspicion was back on the AssemblyFolders registry entry--if the assembly isn't in either GAC that can't be the problem... And then I read through the MSBee output line by line and it says:

Target GetVisualStudioSearchPaths:

"HKEYLOCALMACHINE\Software\Microsoft\VisualStudio\7.1\AssemblyFolders" does not exist in the local machine's registry.

"HKEYLOCALMACHINE\Software\Microsoft\.NetFramework\v2.0.50727\AssemblyFoldersEx\Primary Interop Assemblies" does not exist in the local machine's registry.

So I copied the two libraries' Keys from "HKEYLOCALMACHINE\SOFTWARE\Microsoft\.NETFramework\AssemblyFolders" to there ("...\7.1\..."), and immediately it worked. :-) Was this to be expected? I never had VS2003, so is it likely that these keys would have been added if I had?

However I've just had a look through the installer of the second third-party library (using Orca -- singular!) and there's no reference to "...\7.1\AssemblyFolders"; just "...\.NETFramework\AssemblyFolders" (and apparently some NETCF equivalents). Nor is there in either of the NUnit installers (2.2.7 for 1.1 and 2.0), again they both just set the .NF one. Finally, this document http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dvvstechart/html/vstchmultivercomponent.asp, says that latter path is "for all versions of Visual Studio". (There are also no AssemblyKeyName values either as the document suggests there should). Unless I'm misunderstanding things shouldn't MSBee be including the "...\.NETFramework\AssemblyFolders" location in its search list too?

Alan
Aug 17, 2006 at 12:10 AM
originally posted by Bertan Aygun - MSFT
------------------------------------------------------

Alan,

Which version of MSBee are you using? If you are using the release version (that does not include the latest check ins), could you try the following and let me know if it works:

- In Program Files\MSBuild\MSBee directory, edit MSBuildExtras.FX1_1.Common.targets file. In the target "GetVisualStudioSearchPaths", add the task below as well togethwer with other GetRegistryValue tasks:

<GetRegistryValue
RegistryKey="$(Framework20RegistryBase)\AssemblyFolders"
BaseRegistryKey="HKEYLOCALMACHINE" SearchDepth="1" ContinueOnMissingKey="true">
<Output TaskParameter="RegistryValues" ItemName="FrameworkSearchPaths" />
</GetRegistryValue>

- Also there is a "AssemblySearchPaths" property being set right after GetVisualStudioSearchPaths target. Add the entry "@(FrameworkSearchPaths);" below "@(VisualStudioPIASearchPaths);"

These changes to target file would cause MSBee to look up under those registry keys as well. I cannot try this myself since I never had this problem before. In the meantime I will try to verify that AssemblyFolders subkeys is not already added by other tasks.

If this solves your problem, you can open a work item in CodePlex so that we can track this issue.

Thanks,

Bertan
Aug 17, 2006 at 12:10 AM
originally posted by Alan J. McFarlane
------------------------------------------------------

Yup, I'm using the release version and I'd actually made similar changes myself, having decided that trying to keep the two registry locations synchronised would be too difficult. :-) I added the element:

<GetRegistryValue
RegistryKey="$(Framework20RegistryBase)\$(AssemblyFoldersSuffix)"
BaseRegistryKey="HKEYLOCALMACHINE"
SearchDepth="1"
ContinueOnMissingKey="true">

<Output TaskParameter="RegistryValues" ItemName="VisualStudioSearchPaths" />
</GetRegistryValue>

Similar to yours, but I didn't bother to create the new variable (term?). That worked well (I had removed the 7.1 registry key). When I get a moment I'll add a item at CodePlex.

Thanks

Alan
Aug 17, 2006 at 12:10 AM

originally posted by Alan J. McFarlane
------------------------------------------------------

Have added a work item (#442). I don't know your scheme for Priority so I left it at the default low, I guess its probably a medium. Oh and it seems to 'corrected' the two underscores in the the registry root to be an italic word... :-,)

Alan
Aug 17, 2006 at 12:11 AM
originally posted by Adrigo Gallus
------------------------------------------------------

I not using MSBee yet, but I am encountering the same behaviour with Visual Studio 2003.

My question: what is order (rules) of the places VS 2003 looks for the References of a project when the project is built?


For example, the following is a reference to the nunit.framework.dll in one of my project files -


<Reference
Name = "nunit.framework"
AssemblyName = "nunit.framework"
HintPath = "..\..\Lib\nunit.framework.dll"
/>


The path in HintPath is correct (it is relative to the directory that contains the the above .csproj file), and if resolved would point to the nunit.framework.dll in my Lib directory.

But, VS 2003 property window for the unit.framework reference shows an absolute path to "D:\Program Files\Nunit-Net-2.0 2.2.8\bin\nunit.framework.dll", which is the Nunit directory with assemblies compiled against the .NET 2.0 framework.

What can I do let VS 2003 pick the assembly suggested by the Hintpath?

I cannot use the ReferencePath property from the .user file because we do not check it into our source control.

Lastly, why does not VS 2003 write the strong name of the reference in the .csproj file like VS 2005 does? Can this behavior be changed?

The VS 2005 .csproj file reference to nunit.framework looks like this -

<Reference Include="nunit.framework, Version=2.2.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL" />

Obviously, in this case, there is no possibilty of picking up the wrong assembly. For VS 2003 csproj files, I can add the strong name by editing the .csproj file (in notepad), and it picks up the assembly properly, when that project is loaded., i.e, the following works -

<Reference
Name = "nunit.framework"
AssemblyName = "nunit.framework, Version=2.2.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77"
HintPath = "..\..\Lib\nunit.framework.dll"
/>

I have more detailed posting in Visual Studio General forum.
I really really would appreciate it if some can help me out.