简体   繁体   English

msbuild正在重命名Web.config

[英]Web.config is being renamed by msbuild

I am using VS 2013 to build a webservice. 我正在使用VS 2013来构建Web服务。 When it is built, the Web.config file is being renamed "{projectname}.dll.config". 构建时,Web.config文件将重命名为“{projectname} .dll.config”。

There is a step, _CopyAppConfigFile where it gets renamed, showing in the Output window. 有一个步骤_CopyAppConfigFile,它被重命名,显示在Output窗口中。 I can work around this, by setting the web.config to be copied always, this results in two files, web.config and x.dll.config, which I can live with, but I'd like to avoid it completely if anyone knows how. 我可以解决这个问题,通过设置web.config总是被复制,这会产生两个文件,web.config和x.dll.config,我可以忍受,但我想完全避免它,如果有人知道怎么做。

EDIT: Looks like this is a result of a MSBuild file, located at: 编辑:看起来这是MSBuild文件的结果,位于:

C:\Program Files\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets

I can recreate this in a default install of Visual Studio 2013 in a C# ASP.NET MVC project. 我可以在C#ASP.NET MVC项目中的Visual Studio 2013的默认安装中重新创建它。 I noticed it because I am starting to transition to Visual Studio 2013, but our build server is still on Visual Studio 2012; 我注意到它是因为我开始转换到Visual Studio 2013,但我们的构建服务器仍在Visual Studio 2012上; our setup project was failing after one of my commits because the superfluous config file that I had harvested on my machine was not being generated on the build server. 我的设置项目在我的一次提交后失败了,因为我在我的机器上收获的多余的配置文件没有在构建服务器上生成。

This appears to be a discrepancy between the way things worked in the previous version of MSBuild 4.0 / Visual Studio 2012 and the new version MSBuild 12.0 / Visual Studio 2013. 这似乎是在以前版本的MSBuild 4.0 / Visual Studio 2012和新版本的MSBuild 12.0 / Visual Studio 2013中工作方式之间的差异。

In Visual Studio 2013, the $(ProjectConfigFileName) property is initialized to Web.config [1], which is copied to $(AppConfig) [2], which causes _CopyAppConfigFile to run [3], resulting in an unnecessary config file being named and copied over to the bin directory. 在Visual Studio 2013中, $(ProjectConfigFileName)属性初始化为Web.config [1],它被复制到$(AppConfig) [2],导致_CopyAppConfigFile运行[3],从而导致一个不必要的配置文件被命名并复制到bin目录。

In Visual Studio 2012, the process is similar, except that its version of Microsoft.WebApplication.targets is missing this part that's in the 2013 version: 在Visual Studio 2012中,该过程类似,但其版本的Microsoft.WebApplication.targets缺少此版本的2013版本:

  <!-- Instruct ResolveAssemblyReferences in MS.Common.targets to generate suggested binding redirects. -->
  <PropertyGroup>
        <AutoUnifyAssemblyReferences>false</AutoUnifyAssemblyReferences>
        <AppConfig Condition="'$(AppConfig)' == '' And Exists('$(ProjectConfigFileName)')">$(ProjectConfigFileName)</AppConfig>
  </PropertyGroup>

The key is that AppConfig line. 关键是AppConfig行。 Since that AppConfig reference is missing in the 2012 version, then _CopyAppConfigFile doesn't run under Visual Studio 2012, resulting in the intended behavior (ie, the file is not copied). 由于2012版本中缺少该AppConfig引用,因此_CopyAppConfigFile不会在Visual Studio 2012下运行,从而导致预期的行为(即,不复制该文件)。

In Visual Studio 2013, it looks like they added this line so that the build process could offer to fix up binding redirects for you by double-clicking on them in the Errors list in Visual Studio. 在Visual Studio 2013中,看起来他们添加了这一行,以便构建过程可以通过在Visual Studio的“错误”列表中双击它们来修复绑定重定向。 When Microsoft added this, it seems no one noticed that it resulted in an extra config file being generated and copied to the output folder. 当微软添加这个时,似乎没有人注意到它导致生成额外的配置文件并将其复制到输出文件夹。 So it seems to me as if it is a bug (but a mostly harmless one, since the config file is superfluous) in the new build process in Visual Studio 2013. Since it was conflicting with the Visual Studio 2012 build process on my build server, I added an extra post-build step to blow away the extraneous file: 所以在我看来,在Visual Studio 2013的新构建过程中,好像它是一个bug(但是一个无害的,因为配置文件是多余的)。因为它与我的构建服务器上的Visual Studio 2012构建过程相冲突,我添加了一个额外的后期构建步骤来吹掉无关的文件:

  <Target Name="AfterBuild">
        <Delete ContinueOnError="true" Files="$(TargetPath).config" />
  </Target>

And then you can feel better knowing that it's not a problem with your particular project or system setup, it's just the way Visual Studio 2013 does things now. 然后,您可以感觉更好,因为您知道它不是您的特定项目或系统设置的问题,它只是Visual Studio 2013现在所做的事情。


File locations referenced above: 上面引用的文件位置:

[1] C:\\Program Files (x86)\\MSBuild\\Microsoft\\VisualStudio\\v12.0\\Web\\Microsoft.Web.Publishing.targets [1] C:\\ Program Files(x86)\\ MSBuild \\ Microsoft \\ VisualStudio \\ v12.0 \\ Web \\ Microsoft.Web.Publishing.targets

[2] C:\\Program Files (x86)\\MSBuild\\Microsoft\\VisualStudio\\v12.0\\WebApplications\\Microsoft.WebApplication.targets [2] C:\\ Program Files(x86)\\ MSBuild \\ Microsoft \\ VisualStudio \\ v12.0 \\ WebApplications \\ Microsoft.WebApplication.targets

[3] C:\\Program Files (x86)\\MSBuild\\12.0\\Bin\\Microsoft.Common.CurrentVersion.targets [3] C:\\ Program Files(x86)\\ MSBuild \\ 12.0 \\ Bin \\ Microsoft.Common.CurrentVersion.targets

I think you have the wrong project type. 我认为你有错误的项目类型。 Did you create it as a web project? 您是否将其创建为Web项目? Is this in your csproj file? 这是在你的csproj文件中吗?

{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} {349c5851-65df-11DA-9384-00065b846f21}; {fae04ec0-301f-11D3-bf4b-00c04f79efbc}

From http://www.mztools.com/articles/2008/mz2008017.aspx 来自http://www.mztools.com/articles/2008/mz2008017.aspx

349c5851-65df-11da-9384-00065b846f21 = Web Application fae04ec0-301f-11d3-bf4b-00c04f79efbc = C# Project 349c5851-65df-11da-9384-00065b846f21 = Web应用程序fae04ec0-301f-11d3-bf4b-00c04f79efbc = C#Project

Hth, Ojf Hth,Ojf

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM