从单个C#项目编译的多个dll不在VS2015中编译

时间:2017-08-22 14:26:17

标签: c# visual-studio-2013 visual-studio-2015 msbuild

我有一个项目在构建时将多个类编译到单独的.dll中。每个类都有自己的程序集信息,这些信息在类的名称空间之外定义,例如

[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyDescription("SomeDescription")]

这样,在构建解决方案之后,我可以根据每个.dll创建.nuspec文件,然后根据这些.nuspec文件创建.nupkg文件。

这一切都完美地使用VS2013,但我们的构建机器使用VS2015,它抱怨存在重复的AssemblyVersion,AssemblyFileVersion等等,并且构建失败。

有没有办法允许在VS2015中构建这个我缺失的设置?作为参考,这是我设置用于执行.dll创建的MSBuild目标:

<ItemGroup>
  <BuiltDll Include="Thing\Foo\Bar.cs" />
  <BuiltDll Include="Thing1\Hello\There.cs" />
  <BuiltDll Include="Thing2\How\Ironic.cs" />
</ItemGroup>

<Target Name="CreateDirectories">
   <MakeDir Directories="$(OutputPath)%(BuiltDll.Filename)"></MakeDir>
</Target>

<Target Name="BuildDllsRelease">
  <GetReferenceAssemblyPaths BypassFrameworkInstallChecks="False" 
     TargetFrameworkMoniker=".NETFramework,Version=v4.0">
  <Output TaskParameter="FullFrameworkReferenceAssemblyPaths" 
    PropertyName="path" />
  </GetReferenceAssemblyPaths>
<CSC Sources="@(BuiltDll)" TargetType="library" 
  References="@(PluginReference)" 
  Resources="@(ManifestResourceWithNoCulture);
  @(ManifestNonResxWithNoCultureOnDisk);
  @(CompiledLicenseFile);" 
  OutputAssembly="$(OutputPath)%(BuiltDll.Filename)\%
  (BuiltDll.FileName).dll" EmitDebugInformation="false" />
</Target>

<Target Name="BuildDllsDebug">
  <GetReferenceAssemblyPaths BypassFrameworkInstallChecks="False" 
    TargetFrameworkMoniker=".NETFramework,Version=v4.0">
  <Output TaskParameter="FullFrameworkReferenceAssemblyPaths" 
    PropertyName="path" />
  </GetReferenceAssemblyPaths>
  <CSC Sources="@(BuiltDll)" TargetType="library" 
    References="@(PluginReference)" 
    Resources="@(ManifestResourceWithNoCulture);
    @(ManifestNonResxWithNoCultureOnDisk);@(CompiledLicenseFile);" 
    OutputAssembly="$(OutputPath)%(BuiltDll.FileName).dll" 
    EmitDebugInformation="false" />
 </Target>
 <Target Name="AfterBuild">
   <CallTarget Condition="'$(Configuration)' == 'Debug'" 
     Targets="BuildDllsDebug">
   </CallTarget>
   <CallTarget Condition="'$(Configuration)' == 'Release'" 
     Targets="CreateDirectories;BuildDllsRelease">
   </CallTarget>
</Target>

我能想到的唯一其他选择是为每个我想要dll的文件创建一个单独的项目(但这将意味着超过20个新项目)或者手动创建nuspec文件并将其放在解决方案中而不是之后构建。

0 个答案:

没有答案