如何防止Visual Studio 2012扩展MSBuild 4通配符? [英] How do I prevent Visual Studio 2012 from expanding an MSBuild 4 wildcard?

查看:97
本文介绍了如何防止Visual Studio 2012扩展MSBuild 4通配符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近将我们的构建平台从rake之上的一个古老构建(不要问,很认真)迁移到了一个使用msbuild的构建平台.因为我们的许多团队成员都不使用Visual Studio(同样,不要问),所以他们习惯于将.cs文件放入项目文件夹,并使其神奇地出现在构建中

I recently migrated our build platform from an ancient one build on top of rake (don't ask, seriously) to one using msbuild. Because many of our team members don't use Visual Studio (again, don't ask), they are used to being able to drop in a .cs file into the project folder, and just having it magically appear as part of the build.

因此,此项目的.csproj文件包含以下行:

As such, the .csproj file for this project includes the following line:

<ItemGroup>
    <Compile Include="**\*.cs" Exclude="obj" />
</ItemGroup>

当直接通过msbuild编译时,这非常有用.但是,当我在Visual Studio中打开该项目时,它似乎决定有帮助地"将通配符扩展为文件的完整列表,似乎是在我打开它后立即进行的:

This works great when compiling via msbuild directly. However, when I open the project in Visual Studio, it decides to "helpfully" expand the wildcard into a full list of files, seemingly as soon as I open it:

<ItemGroup>
    <Compile Include="Controller.cs" />
    <Compile Include="MyClass.cs" />
    <Compile Include="MyClass2.cs" />
    <Compile Include="etc/etc/Something.cs" />
    <!-- and so forth -->
</ItemGroup>

尽管从技术上讲这仍然可行,但由于它删除了通配符功能,因此也会引起悲伤.

While technically this still works, it also causes grief because it removes the wildcard ability.

我尝试实施一种技术显示在此页面上,但我无法使其通过简单的编译工作.

I tried implementing a technique shown on this page, but I couldn't get it to work with simple compilation.

以前有人遇到过这个问题吗?有什么办法可以解决这个问题?

Has anyone had this problem before? Is there any way to work around this?

为了弄清我的意思是无法正常工作",这就是我所做的:

To clarify what I mean by "couldn't get it to work", this is what I did:

在Main.csproj中,我有这个:

In Main.csproj, I have this:

<!-- References in here -->
</ItemGroup>

<Import Project="Imports.proj" />

<ItemGroup>
<!-- ProjectReferences down here -->

然后,我用以下代码创建了Imports.proj:

Then, I created Imports.proj, with this:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <ItemGroup>
        <Compile Include="**\*.cs" Exclude="obj" />
    </ItemGroup>
</Project>

当我在Visual Studio中打开Main.csproj时,它不显示任何文件. <Import>行可能是错误的吗?

When I open Main.csproj in Visual Studio, it doesn't show any files. It could be that the <Import> line is wrong?

有趣的是,它仍然通过Visual Studio构建,只是没有将文件显示为项目的一部分.

Edit 2: Interestingly, it still builds through Visual Studio, it just doesn't show the files as part of the project.

推荐答案

我遇到了完全相同的问题,以至于我问了完全相同的问题(

I had the exact same problem, so much so that I asked the exact same question (Unwanted changes in .csproj file on build) 2 days after you did without noticing your own:

虽然我无法解释为什么VS在每次构建项目时都会决定这样做,但我有一个解决方案可供您尝试,这与我如何解决问题的方式相同:

While I can't explain why VS decides to do this every time it builds a project, I do have a solution for you to try, it's identical to how I got around my problem:

<PropertyGroup>
    <IncludePattern>**\*.cs</IncludePattern>
    <ExcludePattern>obj</ExcludePattern>
</PropertyGroup>

<ItemGroup>
   <Compile Include="$(IncludePattern)" Exclude="$(ExcludePattern)" />
</ItemGroup>

VS保留了属性,而没有将通配符扩展到文件的完整列表中

VS leaves properties as they are without expanding the wildcard into a full list of files

这篇关于如何防止Visual Studio 2012扩展MSBuild 4通配符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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