简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM