VS2010 - 使用 分享设置项目之间的属性?(VS2010 - Using

2019-09-22 05:55发布

为什么它不工作<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>

这里的变量只是evaulate为空字符串... :(我敢肯定的路径导入的项目是正确的。


如此看来,当我从命令行运行的MSBuild做工精细,而不是当我建立在Visual Studio中的项目。 为什么在世界上?

Answer 1:

我试图重现和一切工作:

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>

OUTPUT

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文件进行更新或使用的解决方法 。



Answer 2:

它不工作的原因是,Visual Studio中已缓存包含的文件,所以我给它所做的任何更改,直到我重新加载该解决方案或重新启动Visual Studio中并未生效。 这似乎是VS 2010的限制重装VS 2010年以后,一切都按预期。



Answer 3:

该导入元素只有在有效的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>


文章来源: VS2010 - Using to share properties between setup projects?