为什么它不能用于<Import />
这个文件,当它替换语句时只需复制粘贴三个属性就可以了?
../../ Setup.Version.proj
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<InstallerMajorVersion>7</InstallerMajorVersion>
<InstallerMinorVersion>7</InstallerMinorVersion>
<InstallerBuildNumber>7</InstallerBuildNumber>
</PropertyGroup>
</Project>
使用:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<InstallerMajorVersion>7</InstallerMajorVersion>
<InstallerMinorVersion>7</InstallerMinorVersion>
<InstallerBuildNumber>7</InstallerBuildNumber>
<OutputName>asdf-$(InstallerMajorVersion).$(InstallerMinorVersion).$(InstallerBuildNumber)</OutputName>
<OutputType>Package</OutputType>
不起作用:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="../../Setup.Version.proj" />
<PropertyGroup>
<OutputName>asdf-$(InstallerMajorVersion).$(InstallerMinorVersion).$(InstallerBuildNumber)</OutputName>
<OutputType>Package</OutputType>
这里的变量只是简单地用空字符串...... :(我确定导入项目的路径是正确的。
答案 0 :(得分:2)
我试图重现并且一切正常:
<强> importme.proj 强>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<InstallerMajorVersion>7</InstallerMajorVersion>
<InstallerMinorVersion>7</InstallerMinorVersion>
<InstallerBuildNumber>7</InstallerBuildNumber>
</PropertyGroup>
</Project>
<强> main.proj 强>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="importme.proj" />
<PropertyGroup>
<OutputName>asdf-$(InstallerMajorVersion).$(InstallerMinorVersion).$(InstallerBuildNumber)</OutputName>
<OutputType>Package</OutputType>
</PropertyGroup>
<Target Name="Build">
<Message Text="$(OutputName)"/>
</Target>
</Project>
<强>输出强>
Microsoft (R) Build Engine version 4.0.30319.17626
[Microsoft .NET Framework, version 4.0.30319.17626]
Copyright (C) Microsoft Corporation. All rights reserved.
Build started 10.09.2012 12:35:12.
Project "d:\temp\SO\main.proj" on node 1 (default targets).
Build:
asdf-7.7.7
Done Building Project "d:\temp\SO\main.proj" (default targets).
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:00.55
使用
运行msbuild main.proj
更新:您需要为要更新的Include'd文件重新加载项目,或使用workaround。
答案 1 :(得分:2)
它没有工作的原因是Visual Studio缓存了包含的文件,因此我对其所做的任何更改都没有生效,直到我重新加载解决方案或重新启动Visual Studio。这似乎是VS 2010的限制。重新加载VS 2010后,一切都按预期工作。
答案 2 :(得分:0)
Import元素仅在Project
元素下有效。但是,代码似乎想要将值导入<ProjectGroup>
元素。尝试将值声明为Setup.Version.proj中的变量,并在主MSBuild文件中引用它们,例如:
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="../../Setup.Version.proj" /> <!-- Variables declared in here -->
<PropertyGroup>
<InstallerMajorVersion>$(MyInstallerMajorVersion)</InstallerMajorVersion>
<InstallerMinorVersion>$(MyInstallerMinorVersion)</InstallerMinorVersion>
<InstallerBuildNumber>$(MyInstallerBuildNumber)</InstallerBuildNumber>
<OutputName>asdf-$(InstallerMajorVersion).$(InstallerMinorVersion).$(InstallerBuildNumber)</OutputName>
<OutputType>Package</OutputType>