1

There is project with output type as class library, which contains WPF controls. AssemblyInfo.cs should be generated before compile, and for that purpose there is next target (using MSBuild.Community.Tasks) which I imported at the end of .csproj file:

<Target Name="BeforeCompile">
    <AssemblyInfo CodeLanguage="CS"
        OutputFile="Properties\AssemblyInfo.cs"
        AssemblyCompany="..."
        AssemblyCopyright="..."
        ComVisible="false"
        AssemblyVersion="..."
        AssemblyFileVersion="..."  />
</Target>

Before build file AssemblyInfo.cs does not exist.

And the problem is next: when building project from Visual Studio (2015) everything if fine, file is being created, but when I use MSBuild next error shows:

CSC : error CS2001:
Source file '...\Controls.Wpf\Properties\AssemblyInfo.cs' could not be found.
[...\Controls.Wpf\en2zf2n0.tmp_proj]

My hot fix: is to name above target differently (which generates AssemblyInfo), let's say 'GenerateAssemblyInfo', and call it in project file this way, before all the build actions:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="GenerateAssemblyInfo;Build" xmlns="...">

My guess is that happens because when there is xaml files - they need to be compiled into baml (that is why error is in en2zf2n0.tmp_proj, see above), and only after that 'real' build takes place. BeforeCompile happens somewhere between these two steps, and AssemblyInfo is needed before fist step, but there is no such.

Question: What is the difference between building with Visual Studio and MSBuild this this case, and is there any proper (more proper) way to solve this?

Vasyl Senko
  • 1,779
  • 20
  • 33

0 Answers0