生成时对.csproj文件的不需要的更改 [英] Unwanted changes in .csproj file on build

查看:241
本文介绍了生成时对.csproj文件的不需要的更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的一个Web应用程序项目文件中的转换预构建事件中自动检测web.configs,此代码从我的项目文件上移到一个文件夹级别,并在其中获取所有web.configs每个目录和子目录:

I'm trying to auto-detect web.configs as part of a transform pre-build event in one of my web application project files, this code goes up one folder level from my project file and gets all web.configs in every directory and sub directory:

<ItemGroup>
    <WebConfigsRelativePath Include ="..\**\Web.config"/>
</ItemGroup>

这很好用,但是每次我构建和退出Visual Studio时,都会提示我是否要保存对解决方案文件所做的更改.如果我选择是",然后打开项目文件,则上面的代码将更改为每个web.config的位置.

This works great but everytime I build and exit Visual Studio, I get a prompt asking me if I want to save changes made to my solution file. If I select yes, and open the project file, the above code is changed to the locations of each web.config

<ItemGroup>
    <WebConfigsRelativePath Include="..\Web\Decade\Web.config" />
    <WebConfigsRelativePath Include="..\Web\Matrix\RiskAnalysis\Web.config" />
    <WebConfigsRelativePath Include="..\Web\Service\Web.config" />
    <WebConfigsRelativePath Include="..\Web\Web.config" />
</ItemGroup>

这很好,但是我可以自动检测web.configs的全部原因是为了可以随意添加和删除web.configs,而不必对其位置进行硬编码,并且每次退出VS时,位置将硬编码在项目文件中....

This would be fine but the whole reason I'm auto-detecting web.configs pre-build is so I can add and remove web.configs as I please without having to hardcode their locations, and everytime I exit VS, the locations will be hardcoded in the project file....

有人知道为什么我每次退出Visual Studio时都会更改此ItemGroup吗?

Does anyone know why this ItemGroup changes every time I exit Visual Studio?

推荐答案

尽管我无法解释为什么每次构建解决方案时VS决定输出由通配符检索到的文件列表,但我可以向您展示如何获得解决此问题:

While I can't explain why VS decides to output a list of files retrieved by the wildcard each time my solution is built, I can show you how I got around this issue:

<PropertyGroup>
    <WebConfigsSearchString>..\**\Web.config</WebConfigsSearchString>
</PropertyGroup>

<ItemGroup>
    <WebConfigsRelativePath Include ="$(WebConfigsSearchString)"/>
</ItemGroup>

通过在属性(始终保持静态)中定义搜索字符串并在要包含的项目组的文件列表中引用该属性,不会修改项目组代码,但是每次构建已运行

By defining the search string in a property (which always stays static) and referencing the property in the item group's list of files to include, the item group code is never modified but the web.config search is carried out each time a build is run

这篇关于生成时对.csproj文件的不需要的更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆