因为它与App.config中可以Visual Studio会自动调整其他文件的名称? [英] Can Visual Studio automatically adjust the name of other file as it does with app.config?
问题描述
在添加应用程序配置文件,以在Visual Studio .NET项目将被命名为的app.config
键,将其改名为(上构建),以 ApplicationName.config
。
When adding an Application Configuration file to a .Net project in Visual Studio it will be named app.config
and will be renamed (on build) to ApplicationName.config
.
我有大约40个项目的解决方案。我想log4net的功能添加到了不少人。因此,对于每一个项目,我想补充一个文件 app.log4net
。然后,我会宣布一个生成后事件是这样的:
I have a solution with about 40 projects. I want to add log4net functionality to quite a few of them. So for every project I would add a file app.log4net
. I would then declare a post-build event like this:
copy $(ProjectDir)app.log4net $(TargetPath).log4net
这工作得很好。但我不知道是否有一个内置的方式不明确的生成后事件来实现相同的。
That works just fine. But I was wondering whether there was a built-in way to achieve the same without an explicit post-build event.
编辑:虽然我喜欢提出JaredPar和西蒙Mourier这两种解决方案,它们不提供我所希望的。有一个自定义工具或规则的MSBuild这使得它不太透明的(对于该项目其他程序员),至少比用我目前使用的生成后事件更为复杂。不过,我觉得自己的MSBuild将是正确的地方来解决类似的问题。
While I like both solutions proposed by JaredPar and Simon Mourier, they don't provide what I was hoping for. Having a custom tool or MsBuild rule for this makes it less transparent (for other programmers on the project) or at least more complicated than using the post-build event I am currently using. Nevertheless, I feel like MsBuild would be the correct place to solve similar issues.
推荐答案
在这种情况下,它不是Visual Studio的是更新的app.config的名称,而它是一个核心的MSBuild规则,它是独立的Visual Studio。如果你想效仿的app.config模式,这是你应该采取的做法
In this case it's not Visual Studio which is updating the name of app.config but instead it's a core MSBuild rule which is independent of Visual Studio. If you want to emulate the app.config model this is the approach you should take
构建序列的两部分控制的app.config的复制被发现在Microsoft.Common.targets。
The two parts of the build sequence which control the copying of app.config are found in Microsoft.Common.targets.
首先该文件的名称来计算
First the name of the file is calculated
<ItemGroup>
<AppConfigWithTargetPath Include="$(AppConfig)" Condition="'$(AppConfig)'!=''">
<TargetPath>$(TargetFileName).config</TargetPath>
</AppConfigWithTargetPath>
</ItemGroup>
接下来,它实际上是复制作为构建的一部分
Next it is actually copied as a part of the build
<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>
这篇关于因为它与App.config中可以Visual Studio会自动调整其他文件的名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!