Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Bug. NCrunch cannot build project when using build time config transformation
TLogik
#1 Posted : Tuesday, April 12, 2016 11:40:16 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 4/12/2016(UTC)
Posts: 9
Location: Denmark

Was thanked: 2 time(s) in 2 post(s)
If a project is using Build time transformations of web/app config then NCrunch can no longer build the projects.
Error is:
Could not write Destination file: Could not find a part of the path 'C:\LOCALUSERPATH\AppData\Local\NCrunch\6456\5\bin\Debug\VerifyNCrunchBuildFailure.exe.config'.

Steps to reproduce.
I have created a github repo to show the problem.
https://github.com/Logik...NCrunchTestBuildFailure

1. Create a solution. in this case a console app.
2. setup a test
3. enable NCrunch
4. verify that NCrunch runs the test. (this step relates to commit https://github.com/Logik...9ac2ed4bc41bd4431b34540 )
5. use Fast Koala to enable BuildTime transformation of the app config using simple MsBuild tasks in the csproj file. (Fast koala here: https://visualstudiogall...-4bb4-942f-d76526a922a0)
6. Observe that NCrunch can no longer build the project but Visual studio and MSBuild can easily do it without error.
This relates to commit: https://github.com/Logik...633c2a4c44940455f46ce3b

I did not have this issue in earlier version of NCrunch.

This issue is highly problematic and totally voids having NCrunch installed, so i really hope that this will be fixed soon.

System info.
Visual studio 2015 Update 2.
NCrunch 2.20.0.4

Kind regards
Thomas
Remco
#2 Posted : Tuesday, April 12, 2016 12:05:24 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,145

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
Hi Thomas,

Thanks for sharing this issue and the code to reproduce it. A code sample always makes this so much easier to analyse!

The problem is being caused by a faulty build step in your project. The project assumes that the 'bin\debug' directory always exists underneath the project path. The first time a project is built, this isn't true, as the logic is being placed prior to the 'PrepareForBuild' MSBuild target, which is executed before any later build steps have a chance to create this directory.

It's possible to reproduce this problem outside NCrunch by deleting the bin\debug directory, then running MSBuild.exe against the project file. VS doesn't produce this problem because it implicitly creates a bin\debug directory for the project when the project is loaded, so the directory already exists before any IDE builds are started.

It's unlikely that this project will build correctly on a fresh checkout when run on a CI server.

There are a range of ways you can solve this problem:
1. Change the build logic in the project file to create the bin\debug directory prior to the transformations trying to place files there
2. Change the build logic in the project file to perform the transformations later in the build chain, after the primary outputs have been copied to the OutDir
3. Add a dummy file inside the bin\debug directory, then include this file in NCrunch's 'Additional files to include' setting. In this way, NCrunch will create the bin\debug directory with the project's workspace. This is messy but it will solve the problem.
TLogik
#3 Posted : Thursday, April 14, 2016 4:41:12 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 4/12/2016(UTC)
Posts: 9
Location: Denmark

Was thanked: 2 time(s) in 2 post(s)
Hi Remco
I have been in direct communication with the developer/creator of Fast Koala - Jon Davis, and pr. his suggestions i have changed the transformations to happen AfterBuild.

Before:
<Target Name="TransformOnBuild" BeforeTargets="PrepareForBuild">

After:
<Target Name="TransformOnBuild" BeforeTargets="AfterBuild">

Just for brevity i will post the snippet the requires a change here so i do not have to keep the github repo alive forever.


<Target Name="TransformOnBuild" BeforeTargets="AfterBuild">
<PropertyGroup>
<outputTypeExtension Condition="'$(OutputType)' == 'exe' or '$(OutputType)' == 'winexe'">exe</outputTypeExtension>
<outputTypeExtension Condition="'$(OutputType)' == 'Library'">dll</outputTypeExtension>
</PropertyGroup>
<TransformXml Condition="'$(AppCfgType)' == 'Web' and Exists('$(ConfigDir)\Web.Base.config') and Exists('$(ConfigDir)\Web.$(Configuration).config')" Source="$(ConfigDir)\Web.Base.config" Transform="$(ConfigDir)\Web.$(Configuration).config" Destination="Web.config" />
<TransformXml Condition="'$(AppCfgType)' == 'App' and $(InlineAppCfgTransforms) == true and Exists('$(ConfigDir)\App.Base.config') and Exists('$(ConfigDir)\App.$(Configuration).config')" Source="$(ConfigDir)\App.Base.config" Transform="$(ConfigDir)\App.$(Configuration).config" Destination="App.config" />
<TransformXml Condition="'$(AppCfgType)' == 'App' and $(InlineAppCfgTransforms) != true and Exists('App.config') and Exists('App.$(Configuration).config')" Source="App.config" Transform="App.$(Configuration).config" Destination="$(OutDir)$(AssemblyName).$(outputTypeExtension).config" />
<Copy Condition="'$(AppCfgType)' == 'Web' and Exists('$(ConfigDir)\Web.Base.config') and !Exists('$(ConfigDir)\Web.$(Configuration).config')" SourceFiles="$(ConfigDir)\Web.Base.config" DestinationFiles="Web.config" />
<Copy Condition="'$(AppCfgType)' == 'App' and $(InlineAppCfgTransforms) == true and Exists('$(ConfigDir)\App.Base.config') and !Exists('$(ConfigDir)\App.$(Configuration).config')" SourceFiles="$(ConfigDir)\App.Base.config" DestinationFiles="App.config" />
<Copy Condition="'$(AppCfgType)' == 'App' and $(InlineAppCfgTransforms) != true and Exists('App.config') and !Exists('App.$(Configuration).config')" SourceFiles="App.config" DestinationFiles="$(OutDir)$(AssemblyName).$(outputTypeExtension).config" />
</Target>
1 user thanked TLogik for this useful post.
Remco on 4/14/2016(UTC)
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.036 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download