How can I add a specific version of System.XML (2.0.5.0) to my .Net 4 project
I'm making a map editor for my Windows 7 开发者_StackOverflow中文版phone game just in a standard .Net 4 WinForms project.
I've already written the XmlSerialise/Desearilise methods - they live in Load and Save methods on an EntityCollection class within the phone project.
The Windows 7 Phone uses 2.0.5.0 version of System.Xml, System.Xml.Linq and System.Xml.Serialization.
I copied these dlls to a libs directory and tried to reference them from my .Net 4 project - the System.Xml.Serialzation references the 2.0.5.0 as I expected but demands the System.Xml dll - when I reference this from my Libs directory it just ignores me a references the .Net 4 one.
Is there anyway I can force it to reference the 2.0.5.0 one?
Thanks,
Andy
Maybe the option here would be to share only the file between two project (win forms and WP7) as long as the compiler doesn't complain
The only way I know how to reference a specific binary instead of having the project go to the GAC for the DLL is to provide a HintPath in the .csproj file for the reference. It would look something like this:
<Reference Include="System.Xml">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\relative\path\to\lib\folder\System.Xml.dll</HintPath>
</Reference>
You may want to fully qualify the version of System.Xml and set the SpecificVersion to True. You can verify that the specific DLL in your lib folder is being referenced by viewing the Path value in the Properties window of the System.Xml reference in the References folder in Visual Studio.
To reference these specific versions of the assemblies go to the Properties window for each reference and change the Aliases from global to Silverlight. In your class files that reference these assemblies, you can then add per-type aliases or aliased using statements like the following:
extern alias Silverlight;
// Per-type:
using XDocument = Silverlight::System.Xml.Linq;
// Aliased namespace:
using Silverlight::System.Xml.Linq;
This will mean that any time you use the unqualified type XDocument
(or any other type aliased in the same way), it will use the one from the assembly with the matching alias (i.e. your WP7-specific one).
You can also do this inline in your code without adding using statements by qualifying the type accordingly. E.g.
var document = Silverlight::System.Xml.Linq.XDocument.Parse(text);
Under your circumstances, I think aliased namespace using statements are probably your best bet.
精彩评论