将 msbuild 中的编译项移动到单独的文件中?

发布于 2024-12-05 14:58:51 字数 642 浏览 0 评论 0 原文

这可能是一个常见问题解答,但经过大量搜索后我们仍无法找到解决方案。

我们有许多 msbuild 文件,它们都在同一组源文件上运行。 (这不是特别相关,但它们编译到完全不同的平台。)为了使管理更简单,我们希望将 源文件名移动到一个单独的文件并引用该文件来自所有 msbuild 文件。

我们尝试剪切包含 项的 并将其粘贴到新文件中,并用

xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

,然后从原始文件引用该文件

但这不起作用 - 解决方案打开(由于我们破解了默认配置,因此出现警告),但解决方案中没有出现任何项目探险家。

我们做错了什么?

This is probably a FAQ, but we weren't able to find a solution even after a lot of searching.

We have a number of msbuild files that all operate on the same set of source files. (It's not particularly relevant but they compile to completely different platforms.) To make managing these a little simpler, we'd like to move the <Compile> source file names to a separate file and reference that from all the msbuild files.

We tried cutting the <ItemGroup> containing the <Compile> items and pasting it into a new file, and surrounding it with

<Project DefaultTargets="Build" ToolsVersion="3.5" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

and then referencing that file from the original with

<Import Project="Common.files.csproj" />

but that does not work - the solution opens (with a warning since we hacked the default config), but no items appear in the Solution Explorer.

What are we doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

野却迷人 2024-12-12 14:58:51

尝试使用 Visual Studio 2010:

1) 创建外部 .proj(或 .target)文件并添加文件(我使用了不同的项目名称,但这并不重要)

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

2) 在 处导入外部 .proj 文件在 Visual Studio 项目文件顶部

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <Import Project="MyExternalSources.proj" />
   <PropertyGroup>
   ...

并修改 Compile ItemGroup,如下所示:

...
<ItemGroup>
    <Compile Include="@(ExternalCompile)" />
</ItemGroup>
...

警告: 您必须将新项目/文件添加到外部 .项目文件- 从 Visual Studio 中添加的所有项目/文件最终都会像这样:

...
<ItemGroup>
    <Compile Include="@(ExternalCompile)" />
    <Compile Include="MyNewClass.cs" />
</ItemGroup>
...

Tried with Visual Studio 2010:

1) Create your external .proj (or .target) file and add your files (I used a different item name but that shouldn't matter)

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

2) Import your external .proj file at the top of your Visual Studio project file:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <Import Project="MyExternalSources.proj" />
   <PropertyGroup>
   ...

and modify the Compile ItemGroup like this:

...
<ItemGroup>
    <Compile Include="@(ExternalCompile)" />
</ItemGroup>
...

Warning: You'll have to add new items/files to your external .proj file - all items/files added from within Visual Studio will end up like this:

...
<ItemGroup>
    <Compile Include="@(ExternalCompile)" />
    <Compile Include="MyNewClass.cs" />
</ItemGroup>
...
深爱不及久伴 2024-12-12 14:58:51

我从未见过“包含”文件与 MSBuild 一起使用。显然,目标文件以这种方式工作,但我还没有看到另一个文件中包含部分 msbuild 文件。您可以使用如图所示的方法吗?
http://msdn.microsoft.com/en-us/ library/ms171454(VS.80).aspx

使用通配符是我过去解决这个问题的方法。

I've never seen "include" files work with MSBuild. Obviously Targets files work this way, but I haven't seen a partial msbuild file included in another. COuld you use a method such as illustrated in this?
http://msdn.microsoft.com/en-us/library/ms171454(VS.80).aspx

Using wildcards is how I've addressed this in the past.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文