Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio not rebuilding after content file change

I have a unit test project which contains a few XML files for data driven tests. These files are set to Build Action Content and Copy if newer or Copy always.

For the most part, this works fine. However, when I change one of the data files without changing any code, Visual Studio will not trigger a build action at all, and no XML files will be copied. Effectively, I'm running my unit tests with the old data file.

I can trigger a manual build, but I'd like to prevent such mistakes if possible. Is there some way to make Visual Studio (2008) perform the copy operation every time someone changes the content files only?

To clarify: The XML file is inside the unit test project, not in the production code project. I do have a relevant [DeploymentItem] attribute for the file set on the test being run.

like image 350
Thorarin Avatar asked Sep 07 '10 09:09

Thorarin


People also ask

How do I rebuild all in Visual Studio?

To build, rebuild, or clean an entire solutionChoose Build All to compile the files and components within the project that have changed since the most recent build. Choose Rebuild All to "clean" the solution and then builds all project files and components. Choose Clean All to delete any intermediate and output files.

Does rebuild do a clean in Visual Studio?

For the “Rebuild” option, it will “Clean” then “Build” one project at a time in the set build order.

How do I rebuild a Visual Studio project code?

On the menu bar, choose Build, and then choose either Build ProjectName or Rebuild ProjectName. Choose Build ProjectName to build only those project components that have changed since the most recent build. Choose Rebuild ProjectName to "clean" the project and then build the project files and all project components.

What is the difference between build rebuild and clean in Visual Studio?

Build solution: Compiles code files (DLL and EXE) which are changed. Rebuild: Deletes all compiled files and compiles them again irrespective if the code has changed or not. Clean solution: Deletes all compiled files (DLL and EXE file). You can see this YouTube video (Visual Studio Build vs.


3 Answers

I don't know if it'll help in your situation but to get around this I changed Build Action of my XML files to Embedded Resource and it seemed to do the trick.

like image 142
Adam Ruth Avatar answered Oct 12 '22 12:10

Adam Ruth


This seems to simple of an answer, so please forgive me if you've already done it. However I used to have this issue after editing text file data sources.

To fix this I had to clean the project after every change which was annoying on a large project I was working on.

This stopped being needed once I ended up installing VS2008 on a fresh copy of Windows so it may be a configuration issue.

like image 28
Kirk Avatar answered Oct 12 '22 11:10

Kirk


Before running the tests, Visual Studio invokes MSBuild on your project with the Build and Test target. If you look into Microsoft.CSharp.targets (see http://msdn.microsoft.com/en-us/library/ms164312.aspx), you can trace how files from the Content ItemGroup get copied around as part of the bulild process. AFAIK, they are declared inputs and outputs of one of the Bulild sub-targets, so MSBuild should really consider copying them if their timestamps changed.

Can you ensure that: * changes to the files are saved * you are using NTFS * when you run the build from the msbuild cmd-line, does it still not rebuild when an xml file changed?

Visual Studios MSBuild integration is pretty broken, it does obivously not do the straightforward thing of invoking The MSBuild cmd-line. (It has issues with imports being cached and all sorts of crazy, non-intuive things).

like image 37
Johannes Rudolph Avatar answered Oct 12 '22 12:10

Johannes Rudolph