tags:

views:

433

answers:

4

I have two assemblies that unfortunately define the same type in the same namespace. I'm trying to use a an extern alias to work around the problem. In the Visual Studio IDE I have set the "Aliases" property of the reference to my alias. This is supposed to change the C# compiler command line to be something like this:

/reference:MyAlias=MyAssembly.dll

But it doesn't actually do that. The Visual Studio IDE seems to just ignore the Aliases property setting on the reference. So when I go and add the line extern alias MyAlias; at the top of my C# code file I get the error that the alias was not specified in a /reference option to the compiler. I can't figure out what I am doing wrong. Any ideas?

+1  A: 

Working for me in VS2008 using these steps:

  1. Use the properties window to change the alias for the assembly from 'global' to 'MyAlias'
  2. At the top of the file where the aliased assembly is used, put extern alias MyAlias. This must be before any using statements.
  3. Use the alias prefix to use the namespace you want, for example using MyAlias::MyNamespace.
andypaxo
A: 

GentleMen

I am facing the same problem but with vs 2010 c# express . even when running .sln with Msbuild directly aliases are not attached to /reference: switch any solutions?

Thanking you

RIGHT_THEN
Sorry but I never did find a solution to the problem. I ended up changing other parts of the code to eliminate the need for an alias.
Brian Ensink
Thanks Mr. Brian for the info maybe someday somebody finds it.
RIGHT_THEN
A: 

I had exact similar issue, looks like when you clean your solution and build the project, first time MSBuild ignores references and gives error (may be it does not have some assemblies built yet with the references specified), however on second try of the build, it works.

Akash Kava
A: 

I have the same problem and I was able to reproduce the issue.

It turns out reference aliases are ignored on projects containing xaml files which has an xmlns definition to the output assembly like xmlns:local='clr-namespace:TestProject'.

If you think this is your case as well, please vote up my bug report at Microsoft Connect.

EDIT: There is a suggested workaround in the link above which requires editing the project file manually. In order for this to work, I had to give full path of the assembly. Add the following instructions to the end of your project file:

<Target Name="solveAliasProblem" >
<ItemGroup>
 <ReferencePath Remove="FullPath.dll"/>
 <ReferencePath Include="FullPath.dll">
    <Aliases>ourAlias</Aliases>
 </ReferencePath>
</ItemGroup>
</Target>
<PropertyGroup>
    <CoreCompileDependsOn>solveAliasProblem;$(PrepareResourcesDependsOn)</CoreCompileDependsOn>
</PropertyGroup>
orca