Der*_*ler 7 .net msbuild visual-studio-2010 post-build-event visual-studio
将应用程序配置文件添加到Visual Studio中的.Net项目时,它将被命名app.config并将重命名(在构建时)ApplicationName.config.
我有大约40个项目的解决方案.我想在其中的一些中添加log4net功能.因此,对于每个项目,我都会添加一个文件app.log4net.然后我会声明一个这样的post-build事件:
copy $(ProjectDir)app.log4net $(TargetPath).log4net
Run Code Online (Sandbox Code Playgroud)
这很好用.但我想知道是否有一种内置的方法来实现相同的,没有明确的后期构建事件.
编辑:虽然我喜欢JaredPar和Simon Mourier提出的两种解决方案,但他们并不提供我所希望的.拥有自定义工具或MsBuild规则使得它不那么透明(对于项目中的其他程序员)或者至少比使用我当前使用的后期构建事件更复杂.不过,我觉得MsBuild是 解决类似问题的正确方法.
在这种情况下,它不是更新app.config名称的Visual Studio,而是一个独立于Visual Studio的核心MSBuild规则.如果要模拟app.config模型,这是您应该采用的方法
可以在Microsoft.Common.targets中找到控制app.config复制的构建序列的两个部分.
首先计算文件的名称
<ItemGroup>
<AppConfigWithTargetPath Include="$(AppConfig)" Condition="'$(AppConfig)'!=''">
<TargetPath>$(TargetFileName).config</TargetPath>
</AppConfigWithTargetPath>
</ItemGroup>
Run Code Online (Sandbox Code Playgroud)
接下来它实际上被复制为构建的一部分
<Target
Name="_CopyAppConfigFile"
Condition=" '@(AppConfigWithTargetPath)' != '' "
Inputs="@(AppConfigWithTargetPath)"
Outputs="@(AppConfigWithTargetPath->'$(OutDir)%(TargetPath)')">
<!--
Copy the application's .config file, if any.
Not using SkipUnchangedFiles="true" because the application may want to change
the app.config and not have an incremental build replace it.
-->
<Copy
SourceFiles="@(AppConfigWithTargetPath)"
DestinationFiles="@(AppConfigWithTargetPath->'$(OutDir)%(TargetPath)')"
OverwriteReadOnlyFiles="$(OverwriteReadOnlyFiles)"
Retries="$(CopyRetryCount)"
RetryDelayMilliseconds="$(CopyRetryDelayMilliseconds)"
UseHardlinksIfPossible="$(CreateHardLinksForAdditionalFilesIfPossible)"
>
<Output TaskParameter="DestinationFiles" ItemName="FileWrites"/>
</Copy>
</Target>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1044 次 |
| 最近记录: |