none
AssemblyInfo.cs generated in pre-build event.

    Question

  • Using Visual Studio Premium 2012 on Windows 8 Release Preview.

    To start, I already have this line in my .csproj file:

    <UseHostCompilerIfAvailable>false</UseHostCompilerIfAvailable>

    I have a file called SharedAssemblyInfoVersion.cs.  My project has it added as a link using:

    <Compile Include="..\SharedAssemblyInfoVersion.cs">
        <Link>Properties\SharedAssemblyInfoVersion.cs</Link>
    </Compile>

    At the time of build, the file does not exist.  In the pre-build event a batch file is run that creates (or replaces) the file and fills it with:

    using System.Reflection; 
    [assembly: AssemblyVersion("2.0.12.3")] 
    [assembly: AssemblyInformationalVersion("2.0.12.3-gb6523ba")] 

    The problem is that Visual Studio fails the build about the file not existing before the pre-build event has a chance to create it:

    CSC : error CS2001: Source file '..\SharedAssemblyInfoVersion.cs' could not be found

    If I manually create the file first (even if it's empty) Visual Studio will properly replace the file and build with the replacement (thanks to UseHostCompilerIfAvailable being false).

    The first thought I'm sure any readers are having is to just create a placeholder file and leave it there but I want this file to stay out of my version control since it changes with every commit.  I also want a new user to be able to open the project and hit build without running into any errors.

    On top of all that, I would like to avoid adding any external dependencies such as MSBuild Community Tasks, again because I want a new user to be able to just open the project and hit build in VS without installing a bunch of requirements.

    In case it matters, Visual Studio is used for developer builds but MSBuild is used by the build server.
    • Edited by Micah Zoltu Saturday, September 22, 2012 9:40 PM
    Saturday, September 22, 2012 9:39 PM

Answers

  • Sorry, it turns out the issue was there were some other things happening before my script in the pre-build events that were resulting in this problem.  I believe it was when I tried to use gacutil.exe to remove the assembly from the global assembly cache.  Apparently it uses the AssemblyInfo files to do that so if one or more are missing it fails (even if it has enough information from the other AssemblyInfo files.
    • Marked as answer by Micah Zoltu Sunday, September 23, 2012 2:23 AM
    Sunday, September 23, 2012 2:23 AM

All replies

  • Sorry, it turns out the issue was there were some other things happening before my script in the pre-build events that were resulting in this problem.  I believe it was when I tried to use gacutil.exe to remove the assembly from the global assembly cache.  Apparently it uses the AssemblyInfo files to do that so if one or more are missing it fails (even if it has enough information from the other AssemblyInfo files.
    • Marked as answer by Micah Zoltu Sunday, September 23, 2012 2:23 AM
    Sunday, September 23, 2012 2:23 AM
  • Hi Micha71381,

    I’m glad to hear that you got it working.

    Thank you for sharing your solutions & experience here. It will be very beneficial for other community members who have similar questions.

    Best regards,


    Ego [MSFT]
    MSDN Community Support | Feedback to us

    Monday, September 24, 2012 8:41 AM
    Moderator