将msbuild中的编译项移到单独的文件中? [英] Moving compile items in msbuild into a separate file?
问题描述
这可能是一个常见问题解答,但即使经过大量搜索,我们仍无法找到解决方案.
我们有许多msbuild文件,它们都在同一组源文件上运行. (不是特别相关,但是它们可以编译到完全不同的平台上.)为了简化管理,我们希望将<Compile>
源文件名移动到单独的文件中,并从所有msbuild文件中引用该文件.>
我们尝试剪切包含<Compile>
项的<ItemGroup>
并将其粘贴到新文件中,并用
<Project DefaultTargets="Build" ToolsVersion="3.5"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
,然后使用
引用原始文件 <Import Project="Common.files.csproj" />
但这不起作用-解决方案打开(警告,因为我们入侵了默认配置,但出现警告),但是解决方案资源管理器中未显示任何项目.
我们在做什么错了?
尝试使用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>
...
警告::您将必须向外部.proj文件中添加新项目/文件-从Visual Studio中添加的所有项目/文件最终都将像这样:
...
<ItemGroup>
<Compile Include="@(ExternalCompile)" />
<Compile Include="MyNewClass.cs" />
</ItemGroup>
...
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?
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>
...
这篇关于将msbuild中的编译项移到单独的文件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!