Отсутствует DLL при попытке компиляции в двух разных версиях фреймворка в одной команде сборки - PullRequest
2 голосов
/ 10 февраля 2011

У меня есть следующий файл proj:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProductVersion>8.0.30703</ProductVersion>
    <SchemaVersion>2.0</SchemaVersion>
    <ProjectGuid>{4B942FFC-22E5-486B-A3D7-D5EDFFF016F8}</ProjectGuid>
    <OutputType>Library</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>Args</RootNamespace>
    <AssemblyName>Args</AssemblyName>
    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
    <SccProjectName>Svn</SccProjectName>
    <SccLocalPath>Svn</SccLocalPath>
    <SccAuxPath>Svn</SccAuxPath>
    <SccProvider>SubversionScc</SccProvider>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <Framework>NET40</Framework>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release35|AnyCPU'">
    <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\Release3.5\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <ItemGroup>
    <Compile Include="Args.cs" />
    <Compile Include="ArgumentDefinition.cs" />
    <Compile Include="ArgumentParser.cs" />
    <Compile Include="DefaultModelBinder.cs" />
    <Compile Include="IArgumentParser.cs" />
    <Compile Include="IModelBinder.cs" />
    <Compile Include="InternalExtenstions.cs" />
    <Compile Include="ModelBinders.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
    <Compile Include="Properties\Resources.Designer.cs">
      <AutoGen>True</AutoGen>
      <DesignTime>True</DesignTime>
      <DependentUpon>Resources.resx</DependentUpon>
    </Compile>
  </ItemGroup>
  <ItemGroup>
    <EmbeddedResource Include="Properties\Resources.resx">
      <Generator>ResXFileCodeGenerator</Generator>
      <LastGenOutput>Resources.Designer.cs</LastGenOutput>
    </EmbeddedResource>
  </ItemGroup>
  <ItemGroup>
    <Reference Include="System" />
    <Reference Include="System.Core" />
  </ItemGroup>
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
       Other similar extension points exist, see Microsoft.Common.targets.
  <Target Name="BeforeBuild">
  </Target>-->
  <Target Name="AfterBuild">
    <MSBuild Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU'"
     Projects="$(MSBuildProjectFile)"    
     Properties="Configuration=Release35" />
  </Target>
</Project>

Это мой ожидаемый результат при компиляции проекта в Release | AnyCPU:

  • Файл dll и pdb дляпроект, который будет расположен в каталоге bin \ Release, скомпилирован на основе платформы 4.0.
  • Файл dll и pdb для проекта, который будет расположен в каталоге bin \ Release3.5, скомпилирован на основе платформы 3.5.

Я получаю этот результат при сборке проекта;однако, когда я перестраиваю проект, то же самое верно, за исключением того, что dll в каталоге bin \ Release отсутствует.Другие 3 файла (pdb в Release и dll и pdb в Release3.5) все еще там и имеют правильную дату изменения.

Любая помощь будет принята с благодарностью.

Редактировать: После некоторой справки, похоже, что он работает нормально, когда я запускаю MSBuild из командной строки, но когда я запускаю сборку через Visual Studio, то есть когда я получаю описанную выше проблему.

Edit2: Подробный вывод из Visual Studio с командой Rebuild в режиме выпуска.Я был в состоянии опубликовать только «Нормальный» вывод, а не «Подробный» или «Диагностика» из-за длины.Я просмотрел их и не увидел никаких шагов по удалению Args.dll из каталога обычного выпуска ПОСЛЕ того, как он был скомпилирован и скопирован из obj в bin (до компиляции был шаг удаления, но я ожидал, что).

------ Rebuild All started: Project: Args, Configuration: Release Any CPU ------
Build started 2/15/2011 8:23:57 AM.
CoreClean:
  Deleting file "C:\Users\Brian\Documents\Visual Studio 2010\Projects\Args\Args\bin\Release\Args.dll".
  Deleting file "C:\Users\Brian\Documents\Visual Studio 2010\Projects\Args\Args\bin\Release\Args.pdb".
  Deleting file "C:\Users\Brian\Documents\Visual Studio 2010\Projects\Args\Args\obj\Release\Args.Properties.Resources.resources".
  Deleting file "C:\Users\Brian\Documents\Visual Studio 2010\Projects\Args\Args\obj\Release\GenerateResource.read.1.tlog".
  Deleting file "C:\Users\Brian\Documents\Visual Studio 2010\Projects\Args\Args\obj\Release\GenerateResource.write.1.tlog".
  Deleting file "C:\Users\Brian\Documents\Visual Studio 2010\Projects\Args\Args\obj\Release\Args.dll".
  Deleting file "C:\Users\Brian\Documents\Visual Studio 2010\Projects\Args\Args\obj\Release\Args.pdb".
CoreResGen:
  "C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\NETFX 4.0 Tools\resgen.exe" /useSourcePath /r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\mscorlib.dll" /r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Core.dll" /r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.dll" /compile Properties\Resources.resx,obj\Release\Args.Properties.Resources.resources
  Processing resource file "Properties\Resources.resx" into "obj\Release\Args.Properties.Resources.resources".
GenerateTargetFrameworkMonikerAttribute:
Skipping target "GenerateTargetFrameworkMonikerAttribute" because all output files are up-to-date with respect to the input files.
CoreCompile:
  C:\Windows\Microsoft.NET\Framework\v4.0.30319\Csc.exe /noconfig /nowarn:1701,1702 /nostdlib+ /errorreport:prompt /warn:4 /define:TRACE /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\mscorlib.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Core.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.dll" /debug:pdbonly /filealign:512 /optimize+ /out:obj\Release\Args.dll /resource:obj\Release\Args.Properties.Resources.resources /target:library Args.cs ArgumentDefinition.cs ArgumentParser.cs Configuration.cs IInitializeModelBindingStrategy.cs ModelBindingStrategy.cs DefaultModelBinder.cs IArgsTypeConverter.cs IArgumentParser.cs IModelBinder.cs InternalExtenstions.cs InvalidArgsFormatException.cs InvalidModelDefinitionException.cs LambdaArgsTypeConverter.cs ModelBinders.cs Properties\AssemblyInfo.cs Properties\Resources.Designer.cs "C:\Users\Brian\AppData\Local\Temp\.NETFramework,Version=v4.0.AssemblyAttributes.cs"
CopyFilesToOutputDirectory:
  Copying file from "obj\Release\Args.dll" to "bin\Release\Args.dll".
  Args -> C:\Users\Brian\Documents\Visual Studio 2010\Projects\Args\Args\bin\Release\Args.dll
  Copying file from "obj\Release\Args.pdb" to "bin\Release\Args.pdb".
CoreClean:
  Deleting file "C:\Users\Brian\Documents\Visual Studio 2010\Projects\Args\Args\bin\Release3.5\Args.dll".
  Deleting file "C:\Users\Brian\Documents\Visual Studio 2010\Projects\Args\Args\bin\Release3.5\Args.pdb".
  Deleting file "C:\Users\Brian\Documents\Visual Studio 2010\Projects\Args\Args\obj\Release35\Args.Properties.Resources.resources".
  Deleting file "C:\Users\Brian\Documents\Visual Studio 2010\Projects\Args\Args\obj\Release35\ResGen.read.1.tlog".
  Deleting file "C:\Users\Brian\Documents\Visual Studio 2010\Projects\Args\Args\obj\Release35\ResGen.write.1.tlog".
  Deleting file "C:\Users\Brian\Documents\Visual Studio 2010\Projects\Args\Args\obj\Release35\Args.dll".
  Deleting file "C:\Users\Brian\Documents\Visual Studio 2010\Projects\Args\Args\obj\Release35\Args.pdb".
CoreResGen:
  C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\NETFX 4.0 Tools\x64\Tracker.exe @"C:\Users\Brian\AppData\Local\Temp\e35fa3c4055b4fd18515148e01c79912.tmp"  /c "C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\ResGen.exe" /useSourcePath /r:C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorlib.dll /r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.5\System.Core.dll" /r:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll /compile Properties\Resources.resx,obj\Release35\Args.Properties.Resources.resources 
CoreCompile:
  C:\Windows\Microsoft.NET\Framework\v4.0.30319\Csc.exe /noconfig /nowarn:1701,1702 /nostdlib+ /errorreport:prompt /warn:4 /define:TRACE /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorlib.dll /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.5\System.Core.dll" /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll /debug:pdbonly /filealign:512 /optimize+ /out:obj\Release35\Args.dll /resource:obj\Release35\Args.Properties.Resources.resources /target:library Args.cs ArgumentDefinition.cs ArgumentParser.cs Configuration.cs IInitializeModelBindingStrategy.cs ModelBindingStrategy.cs DefaultModelBinder.cs IArgsTypeConverter.cs IArgumentParser.cs IModelBinder.cs InternalExtenstions.cs InvalidArgsFormatException.cs InvalidModelDefinitionException.cs LambdaArgsTypeConverter.cs ModelBinders.cs Properties\AssemblyInfo.cs Properties\Resources.Designer.cs
CopyFilesToOutputDirectory:
  Copying file from "obj\Release35\Args.dll" to "bin\Release3.5\Args.dll".
  Args -> C:\Users\Brian\Documents\Visual Studio 2010\Projects\Args\Args\bin\Release3.5\Args.dll
  Copying file from "obj\Release35\Args.pdb" to "bin\Release3.5\Args.pdb".

Build succeeded.

Time Elapsed 00:00:00.98
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========

Ответы [ 3 ]

3 голосов
/ 17 февраля 2011

Почему

<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> 

находится под основной PropertyGroup, а не только в условиях <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> и <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU'">?

Ммм ... Что произойдет, если вы добавите команду типа

<Exec Command="attrib +r $(TargetPath)"/>

до AfterBuild, PreBuildEvent или BeforeBuild? (Где TargetPath должен быть DLL-файл ...)

1 голос
/ 10 февраля 2011

Я уверен, что это потому, что вы не передаете целевое свойство в вызов AfterBuild то есть когда вы перестраиваете ваше решение в версии, оно делает следующее:

  1. Перестроить - Отпустить (До очистки, Очистить, После очистки, До сборки, Построить, После сборки)
  2. Сборка - Выпуск35

К сожалению, трудно получить запрошенную цель (с помощью командной строки или VS). Если ваша сборка не занимает слишком много времени, я бы порекомендовал всегда проходить целевой Rebuild (или Clean; Build):

<Target Name="AfterBuild">
  <MSBuild Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU'"
   Projects="$(MSBuildProjectFile)"
   Targets="Clean;Build"
   Properties="Configuration=Release35" />
</Target>
1 голос
/ 10 февраля 2011

Не удалось воспроизвести вашу проблему. Я использовал MSbuild.exe из framework 3.5 и 4.0 в режиме

MSbuild.exe yourproject.csproj /p:Configuration=Release /t:Build
MSbuild.exe yourproject.csproj /p:Configuration=Release /t:Rebuild

Единственное, что я могу порекомендовать, это позвонить в подробном режиме с флагом / v: diag .

И попробуйте отключить вызов цели AfterBuild.

РЕДАКТИРОВАТЬ: Вам действительно нужно скомпилировать обе версии в IDE?

Если нет, я могу порекомендовать отключить сборку внутри IDE и оставить ее для скрипта сборки:

  <Target Name="AfterBuild"
          Condition="'$(BuildingInsideVisualStudio)'!='true'" >
    <MSBuild Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU'"
     Projects="$(MSBuildProjectFile)"    
     Targets="Clean;Build"
     Properties="Configuration=Release35" />
  </Target>

РЕДАКТИРОВАТЬ: Попробуйте ProcMon с фильтром " Имя процесса is devenv.exe " и посмотреть активность ввода-вывода файла для bin \ Release \ Args.dll во время перестройки.

Попробуйте найти диагностический вывод в VS для bin \ Release \ Args.dll . Вы увидите каждое действие перемещения / переименования / удаления с этим файлом.

Диагностический журнал показывает, что все должно быть в порядке:

Task "Copy"
  Copying file from "obj\Release\Args.dll" to "bin\Release\Args.dll".
Done executing task "Copy".
Task "Message"
  Args -> C:\Users\Brian\Documents\Visual Studio     2010\Projects\Args\Args\bin\Release\Args.dll
Done executing task "Message".

Журнал показывает, что нет никаких внешних помех от других инструментов. Даже с полными данными я не смог воспроизвести вашу проблему.

Чтобы построить обе конфигурации из VS, я могу предложить создать дополнительный файл Targets в каталоге Args с именем BuildArgs.csproj и добавить его в VS sln:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build"     xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <BuildingProject>$(MSBuildProjectDirectory)\Args.csproj</BuildingProject>
  </PropertyGroup>
  <ItemGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
     <BuildConfigurations Include="Release">
        <Visible>False</Visible>
     </BuildConfigurations>    
     <BuildConfigurations Include="Release35">
        <Visible>False</Visible>
     </BuildConfigurations>
  </ItemGroup>
  <ItemGroup Condition=" '$(Configuration)|$(Platform)' == 'Release35|AnyCPU'">
     <BuildConfigurations Include="Release35">
        <Visible>False</Visible>
     </BuildConfigurations>
  </ItemGroup>
  <ItemGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
     <BuildConfigurations Include="Debug">
        <Visible>False</Visible>
     </BuildConfigurations>    
  </ItemGroup>

  <Target Name="Build"
          Condition="'@(BuildConfigurations)'!=''"
          Inputs="%(BuildConfigurations.Identity)"
          Outputs="_Non_Existent_Item_To_Batch_">
    <Message Text="Building Configuration %(BuildConfigurations.Identity)" Importance="high" />
    <MSBuild 
        Targets="Build" 
        Projects="$(BuildingProject)" 
        Properties="Configuration=%(BuildConfigurations.Identity)" />
  </Target>

  <Target Name="Rebuild"
          Condition="'@(BuildConfigurations)'!=''"
          Inputs="%(BuildConfigurations.Identity)"
          Outputs="_Non_Existent_Item_To_Batch_">
    <Message Text="Rebuilding Configuration %(BuildConfigurations.Identity)" Importance="high" />
    <MSBuild 
        Targets="Rebuild" 
        Projects="$(BuildingProject)" 
        Properties="Configuration=%(BuildConfigurations.Identity)" />
  </Target>

  <Target Name="Clean"
          Condition="'@(BuildConfigurations)'!=''"
          Inputs="%(BuildConfigurations.Identity)"
          Outputs="_Non_Existent_Item_To_Batch_">
    <Message Text="Cleaning Configuration %(BuildConfigurations.Identity)"     Importance="high" />
    <MSBuild 
        Targets="Clean" 
        Projects="$(BuildingProject)" 
        Properties="Configuration=%(BuildConfigurations.Identity)" />
  </Target>
</Project>

Он будет реагировать на каждую команду построения VS. Вы можете уменьшить его только для сборки только Release35 конфигурация при сборке конфигурации = релиз в VS. Такой сценарий абсолютно универсален для построения любого проекта.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...