2

Why doesn't it work to <Import /> this file, when it works when I replace the statement with just copy-pasting the three properties?

../../Setup.Version.proj

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
        <InstallerMajorVersion>7</InstallerMajorVersion>
        <InstallerMinorVersion>7</InstallerMinorVersion>
        <InstallerBuildNumber>7</InstallerBuildNumber>
    </PropertyGroup>
</Project>

Works:

<?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>

Doesn't work:

<?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>

Here the variables just evaulate to empty strings... :( I'm certain the path to the imported project is correct.


So it seems to work fine when i run msbuild from the command line, but not when I build the project inside Visual Studio. Why in the world?

3 Answers3

2

I've tried to reproduce and everything works:

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

Run using

msbuild main.proj

UPDATE: You need to reload project for Include'd files to be updated or use workaround.

Community
  • 1
  • 1
Pavel Krymets
  • 6,253
  • 1
  • 22
  • 35
2

The reason it didn't work is that Visual Studio had cached the included file, so that any changes I made to it didn't take effect until I reloaded the solution or restarted Visual Studio. This seems to be a limitation of VS 2010. After reloading VS 2010, everything worked as expected.

0

The Import element is only valid under the Project element. However, the code appears to want to import the values into a <ProjectGroup> element. Try declaring the values as variables in Setup.Version.proj and reference them in your main MSBuild file, such as:

<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>
akton
  • 14,148
  • 3
  • 43
  • 47
  • Darn, they're still not defined. I can't find any good examples of this online either... –  Sep 08 '12 at 18:21
  • @arex1337 Can you post the contents of your Setup.Version.proj file, please? – akton Sep 09 '12 at 01:38
  • @arex1337 Hmm. The only thing I can think of is perhaps order of operations (http://msdn.microsoft.com/en-us/library/ms171464.aspx). If I think of anything else, I'll let you know. – akton Sep 09 '12 at 05:40
  • In Setup.Version.proj you define `7` However in your main project file you reference `$(MyInstallerMajorVersion)` Try fixing Setup.Version.proj and see what happens. – JakeSays Sep 09 '12 at 16:05
  • I think you may have mistaken one of the answers for my question. I don't reference $(MyInstallerMajorVersion). I did try akton's suggestion too, without any success. –  Sep 09 '12 at 16:57