msbuildmonoxbuild

MSBuild / XBuild differences regarding $(ProjectName)?


I'm attempting to define a cross platform build project for Windows/Mono. Part of the build process creates nuget packages when compiling in release mode.

Here is my "AfterBuild" target:

  <Target Name="AfterBuild" Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <PropertyGroup>
      <LocalPackagesDir Condition=" '$(LocalPackagesDir)' == '' ">$(TEMP)</LocalPackagesDir>
      <OutputPackageDir>nuget\</OutputPackageDir>
      <NuspecFile>nuget\$(ProjectName).nuspec</NuspecFile>
    </PropertyGroup>

    <Message Importance="High" Text="Building nuget package:  $(NuspecFile) ..." />
    <Exec Command="nuget pack $(NuspecFile) -OutputDirectory $(OutputPackageDir)" />

    <ItemGroup>
      <BuiltPackage Include="nuget\**\$(ProjectName)*.nupkg" />
    </ItemGroup>

    <Message Importance="High" Text="Copying nuget package: @(BuiltPackage) in local packages repository: $(LocalPackagesDir) ..." />
    <Copy SourceFiles="@(BuiltPackage)" DestinationFolder="$(LocalPackagesDir)" />
  </Target>

This works perfectly with MSBuild/Windows but fails under Mono because $(ProjectName) is empty. Are there fundamental differences in the way build script variables are treated between MSBuild/XBuild?


Solution

  • Try adding a fallback value manually, such as MyFallback.Project.Name below.

    <?xml version="1.0" encoding="utf-8"?>
    <Project>
        <PropertyGroup>
            <ProjectName Condition=" '$(ProjectName)' == '' ">MyFallback.Project.Name</ProjectName>
        </PropertyGroup>
        <!-- The rest of the file... -->
    </Project>
    

    Running msbuild directly already worked, and this fixed building through Xamarin Studio on Mac.