Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

visual studio c# does not build files that were change by pre-build event

I have solution in visual studio 2010 c#. In the pre build event I execute command that change files in this solution. The updated file is not built in the current build. How can I do that the file, with the changes, will be built in the current build???

Thanks.

like image 285
user2717436 Avatar asked Dec 02 '13 07:12

user2717436


Video Answer


1 Answers

Ok, it seems i figured out your issue.

I have set up a simple Console app and this event:

<PreBuildEvent>copy "D:\Program.cs" "D:\Projects\PreBuildFileModification\FileModification\Program.cs" /Y</PreBuildEvent>

And alas, this does not work! (copy happens and updates file on disk, but Visual Studio does not detect these changes and loads cached file).

Solution is to add:

<UseHostCompilerIfAvailable>false</UseHostCompilerIfAvailable>

In your configuration, eg:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
  <PlatformTarget>x86</PlatformTarget>
  <DebugType>pdbonly</DebugType>
  <Optimize>true</Optimize>
  <OutputPath>bin\Release\</OutputPath>
  <DefineConstants>TRACE</DefineConstants>
  <ErrorReport>prompt</ErrorReport>
  <WarningLevel>4</WarningLevel>
  <UseHostCompilerIfAvailable>false</UseHostCompilerIfAvailable>
</PropertyGroup>

And now this works like a charm.

Thanks to Rob Butterworth

like image 83
Aleksei Poliakov Avatar answered Oct 05 '22 22:10

Aleksei Poliakov