How to include an auto generated file in a MsBuild project?

1.8k views Asked by At

Using MsBuild 4.0 I included a pre-build event that generates one of the project source files. But it seeks for the file before it is generated:

error CS1504: Source file 'c:\src\Data\Main.Designer.cs' could not be opened ('Unspecified error ')

The file is generated by DbMetal/SqlMetal. Is there any way to make this work?

1

There are 1 answers

0
Sergio Rykov On BEST ANSWER

Move your action to BeforeBuild target. In the project *.csproj it is by default commented. Uncomment it and call DBMetal using Exec task

<Target Name="BeforeBuild">
    <Exec Command="<your prebuild action 1>"/>
    <Exec Command="<your prebuild action 2>"/>
</Target>

If you are working with Datasource.db and want to generate Main.Designer.cs you can specify Input and Output parameters for the target. It will saves you calling DBMetal and rebuilding the project itself.

<Target Name="BeforeBuild"
        Inputs="Datasource.db"
        Outputs="Main.Designer.cs">
    <Exec Command="<your prebuild action 1>"/>
    <Exec Command="<your prebuild action 2>"/>
</Target>