Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It's not possible to rebuild a project with Umbraco Forms and RazorCompileOnBuild set to true #738

Closed
Nashuim opened this issue Mar 3, 2022 · 6 comments

Comments

@Nashuim
Copy link

Nashuim commented Mar 3, 2022

Which exact Umbraco version are you using? For example: 9.0.1 - don't just write v9

9.3.1

Bug summary

It seems that there's some issues with the Umbraco Forms targets that only appear if you try to rebuild the project. Calling clean and then build work fine.
This happens in both visual studio and msbuild with /t:rebuild and only if you're compiling razor views on build.

Specifics

You get a error similar to this but the file seems to change:
Could not find a part of the path 'C:\play\UmbracoFormsTest\Views\Partials\Forms\Themes\default\Fieldtypes\FieldType.Recaptcha2.cshtml'. at System.IO.FileStream.ValidateFileHandle(SafeFileHandle fileHandle) at System.IO.FileStream.CreateFileOpenHandle(FileMode mode, FileShare share, FileOptions options) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) at Microsoft.AspNetCore.Razor.Language.DefaultRazorProjectItem.Read() at Microsoft.AspNetCore.Razor.Language.RazorSourceDocument.ReadFrom(RazorProjectItem projectItem) at Microsoft.AspNetCore.Razor.Language.DefaultRazorProjectEngine.CreateCodeDocumentCore(RazorProjectItem projectItem, Action1 configureParser, Action1 configureCodeGeneration) at Microsoft.AspNetCore.Razor.Language.DefaultRazorProjectEngine.CreateCodeDocumentCore(RazorProjectItem projectItem) at Microsoft.AspNetCore.Razor.Language.RazorProjectEngine.Process(RazorProjectItem projectItem) at Microsoft.AspNetCore.Razor.Tools.GenerateCommand.<>c__DisplayClass52_0.<GenerateCode>b__0(Int32 i) at System.Threading.Tasks.Parallel.<>c__DisplayClass19_01.<ForWorker>b__1(RangeWorker& currentWorker, Int32 timeout, Boolean& replicationDelegateYieldedBeforeCompletion) --- End of stack trace from previous location --- at System.Threading.Tasks.Parallel.<>c__DisplayClass19_01.<ForWorker>b__1(RangeWorker& currentWorker, Int32 timeout, Boolean& replicationDelegateYieldedBeforeCompletion) at System.Threading.Tasks.TaskReplicator.Replica1.ExecuteAction(Boolean& yieldedBeforeCompletion) at System.Threading.Tasks.TaskReplicator.Replica.Execute()

Steps to reproduce

  • Create a new project with dotnet new umbraco --name MyProject
  • Add Umbraco.Forms to the project
  • Build to get the Umbraco files
  • Switch RazorCompileOnBuild to true
  • Rebuild

Expected result / actual result

No response

@nul800sebastiaan nul800sebastiaan transferred this issue from umbraco/Umbraco-CMS Mar 8, 2022
@nul800sebastiaan
Copy link
Member

Thanks @Nashuim - this looks like an issue specific to Forms, so I've moved it to the appropriate tracker for the team to pick up soon! Thanks for the report! 👍

@AndyButland
Copy link

I couldn't replicate this with the latest release of Forms. We did make some amends to the targets file in that version for another issue, so perhaps it's resolved this too. But let me replay what I've done and if you think I've missed something that will show the issue please can you let me know?

  • dotnet new umbraco --name Forms738Test
  • cd .\Forms738Test\
  • Updated the .csproj to make these two amends:
    • Added reference to Umbraco Forms with <PackageReference Include="Umbraco.Forms" Version="9.3.0" />
    • Updated <RazorCompileOnBuild>true</RazorCompileOnBuild>
  • Tried multiple dotnet build and dotnet clean commands but not seeing any error.

@Nashuim
Copy link
Author

Nashuim commented Mar 9, 2022

This doesn't happen on Build. It's specifically for Rebuild. Try doing a rebuild using Visual Studio or alternatively try dotnet msbuild /t:rebuild.

@xdjoshuaaz
Copy link

xdjoshuaaz commented Mar 9, 2022

I'm also experiencing build errors when RazorCompileOnBuild is set to true. It only happens when Rebuild is executed in VS or using dotnet build /t:Rebuild. Running dotnet clean then dotnet build separately doesn't cause this error.

We're using Umbraco 9.3.1, Umbraco Forms 9.3.0.

Errors:

CSC : error CS2001: Source file '$(MSBuildProjectDirectory)\Views\MacroPartials\InsertUmbracoFormWithTheme.cshtml' could not be found. [$(MSBuildProjectDirectory)\$(MSBuildProjectFile)]
CSC : error CS2001: Source file '$(MSBuildProjectDirectory)\Views\MacroPartials\RenderUmbracoFormScripts.cshtml' could not be found. [$(MSBuildProjectDirectory)\$(MSBuildProjectFile)]
CSC : error CS2001: Source file '$(MSBuildProjectDirectory)\Views\Partials\Forms\Emails\Example-Template.cshtml' could not be found. [$(MSBuildProjectDirectory)\$(MSBuildProjectFile)]
CSC : error CS2001: Source file '$(MSBuildProjectDirectory)\Views\Partials\Forms\Export\excel.cshtml' could not be found. [$(MSBuildProjectDirectory)\$(MSBuildProjectFile)]
CSC : error CS2001: Source file '$(MSBuildProjectDirectory)\Views\Partials\Forms\Themes\bootstrap3-horizontal\Fieldtypes\FieldType.RadioButtonList.cshtml' could not be found. [$(MSBuildProjectDirectory)\$(MSBuildProjectFile)]
CSC : error CS2001: Source file '$(MSBuildProjectDirectory)\Views\Partials\Forms\Themes\bootstrap3-horizontal\Form.cshtml' could not be found. [$(MSBuildProjectDirectory)\$(MSBuildProjectFile)]
CSC : error CS2001: Source file '$(MSBuildProjectDirectory)\Views\Partials\Forms\Themes\default\DatePicker.cshtml' could not be found. [$(MSBuildProjectDirectory)\$(MSBuildProjectFile)]
CSC : error CS2001: Source file '$(MSBuildProjectDirectory)\Views\Partials\Forms\Themes\default\Fieldtypes\FieldType.CheckBox.cshtml' could not be found. [$(MSBuildProjectDirectory)\$(MSBuildProjectFile)]
CSC : error CS2001: Source file '$(MSBuildProjectDirectory)\Views\Partials\Forms\Themes\default\Fieldtypes\FieldType.CheckBoxList.cshtml' could not be found. [$(MSBuildProjectDirectory)\$(MSBuildProjectFile)]
CSC : error CS2001: Source file '$(MSBuildProjectDirectory)\Views\Partials\Forms\Themes\default\Fieldtypes\FieldType.DataConsent.cshtml' could not be found. [$(MSBuildProjectDirectory)\$(MSBuildProjectFile)]
CSC : error CS2001: Source file '$(MSBuildProjectDirectory)\Views\Partials\Forms\Themes\default\Fieldtypes\FieldType.DatePicker.cshtml' could not be found. [$(MSBuildProjectDirectory)\$(MSBuildProjectFile)]
CSC : error CS2001: Source file '$(MSBuildProjectDirectory)\Views\Partials\Forms\Themes\default\Fieldtypes\FieldType.DropDownList.cshtml' could not be found. [$(MSBuildProjectDirectory)\$(MSBuildProjectFile)]
CSC : error CS2001: Source file '$(MSBuildProjectDirectory)\Views\Partials\Forms\Themes\default\Fieldtypes\FieldType.FileUpload.cshtml' could not be found. [$(MSBuildProjectDirectory)\$(MSBuildProjectFile)]
CSC : error CS2001: Source file '$(MSBuildProjectDirectory)\Views\Partials\Forms\Themes\default\Fieldtypes\FieldType.HiddenField.cshtml' could not be found. [$(MSBuildProjectDirectory)\$(MSBuildProjectFile)]
CSC : error CS2001: Source file '$(MSBuildProjectDirectory)\Views\Partials\Forms\Themes\default\Fieldtypes\FieldType.PasswordField.cshtml' could not be found. [$(MSBuildProjectDirectory)\$(MSBuildProjectFile)]
CSC : error CS2001: Source file '$(MSBuildProjectDirectory)\Views\Partials\Forms\Themes\default\Fieldtypes\FieldType.RadioButtonList.cshtml' could not be found. [$(MSBuildProjectDirectory)\$(MSBuildProjectFile)]
CSC : error CS2001: Source file '$(MSBuildProjectDirectory)\Views\Partials\Forms\Themes\default\Fieldtypes\FieldType.Recaptcha2.cshtml' could not be found. [$(MSBuildProjectDirectory)\$(MSBuildProjectFile)]
CSC : error CS2001: Source file '$(MSBuildProjectDirectory)\Views\Partials\Forms\Themes\default\Fieldtypes\FieldType.Recaptcha3.cshtml' could not be found. [$(MSBuildProjectDirectory)\$(MSBuildProjectFile)]
CSC : error CS2001: Source file '$(MSBuildProjectDirectory)\Views\Partials\Forms\Themes\default\Fieldtypes\FieldType.Text.cshtml' could not be found. [$(MSBuildProjectDirectory)\$(MSBuildProjectFile)]
CSC : error CS2001: Source file '$(MSBuildProjectDirectory)\Views\Partials\Forms\Themes\default\Fieldtypes\FieldType.Textarea.cshtml' could not be found. [$(MSBuildProjectDirectory)\$(MSBuildProjectFile)]
CSC : error CS2001: Source file '$(MSBuildProjectDirectory)\Views\Partials\Forms\Themes\default\Fieldtypes\FieldType.Textfield.cshtml' could not be found. [$(MSBuildProjectDirectory)\$(MSBuildProjectFile)]
CSC : error CS2001: Source file '$(MSBuildProjectDirectory)\Views\Partials\Forms\Themes\default\Form.cshtml' could not be found. [$(MSBuildProjectDirectory)\$(MSBuildProjectFile)]
CSC : error CS2001: Source file '$(MSBuildProjectDirectory)\Views\Partials\Forms\Themes\default\Render.cshtml' could not be found. [$(MSBuildProjectDirectory)\$(MSBuildProjectFile)]
CSC : error CS2001: Source file '$(MSBuildProjectDirectory)\Views\Partials\Forms\Themes\default\Script.cshtml' could not be found. [$(MSBuildProjectDirectory)\$(MSBuildProjectFile)]
CSC : error CS2001: Source file '$(MSBuildProjectDirectory)\Views\Partials\Forms\Themes\default\ScrollToFormScript.cshtml' could not be found. [$(MSBuildProjectDirectory)\$(MSBuildProjectFile)]
CSC : error CS2001: Source file '$(MSBuildProjectDirectory)\Views\Partials\Forms\Themes\default\Submitted.cshtml' could not be found. [$(MSBuildProjectDirectory)\$(MSBuildProjectFile)]

The build fails in the CoreCompile target.

It seems that the views are being deleted in the Forms ClearUmbracoFormsViews target but not being copied across to the Views folder before the CoreCompile target runs. The Forms CopyUmbracoFormsViews target is responsible for copying views.

Because running a clean then a build sequentially works correctly, I suspect that the CopyUmbracoFormsViews target needs to run earlier in rebuild scenarios.

@xdjoshuaaz
Copy link

Adding <Target Name="EnsureUmbracoFormsRazorFilesCopiedBeforeBuild" DependsOnTargets="CopyUmbracoFormsViews" BeforeTargets="PrepareForBuild" AfterTargets="ClearUmbracoFormsViews"></Target> to the project file seems to work around the issue 😊

@AndyButland
Copy link

Thanks for the clarification and suggestions both. I can replicate with a rebuild as you say, and looks like we can resolve by amending the timing of the "copy views" step. We'll test and get this updated in a future release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants