我有以下项目文件:
<?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中编译项目时的预期结果:
我在构建项目时得到了这个结果;但是,当我重建项目时,除了bin \ Release目录中的dll丢失之外,情况也是如此。其他3个文件(Release中的pdb和Release3中的dll和pdb)仍然存在且具有正确的修改日期。
任何帮助都会非常感激。
修改 在一些帮助之后,当我从命令行运行MSBuild时看起来它工作正常,但是当我通过Visual Studio运行构建时,就是当我遇到上面描述的问题时。
EDIT2: Visual Studio中的详细输出以及在发布模式下使用Rebuild命令。由于长度的原因,我只能发布“正常”输出,而不是“详细”或“诊断”。我确实仔细研究了这些,并且在编译并从obj复制到bin之后我没有看到从常规版本目录中删除Args.dll的任何步骤(在编译之前有一个删除步骤,但我希望)。
------ 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 ==========
答案 0 :(得分:3)
为什么
<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 :(得分:1)
无法重现您的问题。 我在模式
中使用了框架3.5和4.0中的MSbuild.exeMSbuild.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>
编辑:使用过滤器“进程名称 devenv.exe ”尝试ProcMon并查看 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构建两个配置,我可以建议在名为 BuildArgs.csproj 的Args目录中创建其他Targets文件,并将其添加到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 build命令。您可以减少它只是为了构建Release35 在VS中构建Configuration = Release时的配置。这种脚本对于构建任何项目都是绝对通用的。
答案 2 :(得分:1)
我很确定这是因为您没有将目标属性传递给AfterBuild调用 即,当您在发布中重建您的解决方案时,它会执行以下操作:
不幸的是,很难获得所请求的目标(通过命令行或VS)。如果您的构建不花费太多时间,我建议总是传递目标Rebuild(或Clean; Build):
<Target Name="AfterBuild">
<MSBuild Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU'"
Projects="$(MSBuildProjectFile)"
Targets="Clean;Build"
Properties="Configuration=Release35" />
</Target>