问题
I am attempting to solve the well known problem of automatically generated serialization assemblies in VS 2010, both VB.NET and C#. The "Generate Serialization Assemblies" option in project settings does nothing for non-web projects (see http://blog.devstone.com/aaron/archive/2008/02/07/2778.aspx et al). Thus the calls to serializers generate file i/o exceptions that are very unfortunate, and for which there is no cure. The method suggested above does not appear to work with VS2010 and SGEN still runs with /proxytypes enabled.
回答1:
Solution:
Set "Generate Serialization Assemblies" in project settings to ON as usual, then add this xml into the .proj file:
<PropertyGroup>
<SGenUseProxyTypes>false</SGenUseProxyTypes>
<SGenPlatformTarget>$(Platform)</SGenPlatformTarget>
</PropertyGroup>
The first line turns off the evil /proxytypes switch. The second line is required if the platform that is selected is anything other than AnyCPU. If it is omitted, then the serialization assembly is built with AnyCPU and will fail to bind to the main assembly that may be x86 or x64.
来源:https://stackoverflow.com/questions/9766655/xml-serialization-assembly-for-non-web-projects