Nuget throws "Could not find a part of the path" error - vb.net

I have a VB.NET solution in Visual Studio 2013. I am using Nuget v2.12.0.817 (this is the lastest version available for Visual Studio 2013).
When I compile the solution I get an error that says:
Could not find a part of the path
I googled and it seems it is a problem with Nuget. I have done what was explained here as a workaround but without success. It consists on changing the space after $(SolutionDir) to a backslash in nuget.targets. My nuget.targets is as below:
<PaddedSolutionDir Condition=" '$(OS)' == 'Windows_NT'">"$(SolutionDir) "</PaddedSolutionDir>
<PaddedSolutionDir Condition=" '$(OS)' != 'Windows_NT' ">"$(SolutionDir)"</PaddedSolutionDir>
Also, I have tried to change the 2 lines above to:
<PaddedSolutionDir Condition=" '$(OS)' == 'Windows_NT' and HasTrailingSlash('$(SolutionDir)')">"$(SolutionDir)\"</PaddedSolutionDir>
<PaddedSolutionDir Condition=" '$(OS)' == 'Windows_NT' and !HasTrailingSlash('$(SolutionDir)')">"$(SolutionDir)"</PaddedSolutionDir>
<PaddedSolutionDir Condition=" '$(OS)' != 'Windows_NT' ">"$(SolutionDir)"</PaddedSolutionDir>
But Nuget continues adding a blank space at the end of the path and it does not work... Any ideas?
UPDATE 25/11/2019:
I updated VS 2013 to Update 5 some days ago and suddenly it started compiling correctly. Today I have compiled the solution again, and now again the error still continues appearing. I have installed Nuget 2.12.0.817 (the last available for VS2013). I do not understand anything...

Related

MSBuild change property based on build target

I want to know whether the platform I'm building to is OSX. While I have gotten a working solution, it requires me to specify -r and -p:RuntimeIdentifier, and is also incredibly fragile. I know this isn't the right way to do it.
Right now I have something like
<IsOSX Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))' == 'true'">true</IsOSX>
<BuildingForOSX Condition="'$(RuntimeIdentifier.StartsWith(`osx`))' Or (('$(IsOSX)' == 'true') And ('$(RuntimeIdentifier)' == ''))">true</BuildingForOSX>
<BeautyEnable Condition="('$(BeautyEnable)' == '') And ('$(BuildingForOSX)' == 'true')">false</BeautyEnable>
<BeautyEnable Condition="'$(BeautyEnable)' == ''">true</BeautyEnable>
with
<PackageReference Condition="'$(BuildingForOSX)' == 'true'" Include="Dotnet.Bundle" Version="*" />
<PackageReference Condition="'$(BeautyEnable)' == 'true'" Include="nulastudio.NetBeauty" Version="2.0.0.0-beta.1" />
The goal is to:
Only download Bundle when the target platform is OSX
Only enable NetBeauty when the target platform is not OSX
What's the proper way to do this that makes both:
dotnet restore -r osx-arm64 work without -p:RuntimeIdentifier=osx-arm64, and
dotnet msbuild -p:RuntimeIdentifier=osx-arm64 -t:BundleApp work without applying NetBeauty?

MSBuild Error task show up as a warning in VS

I have an Error task in a C# MSBuild project. The error shows up as a warning in VS2022, below a huge number of other errors that are directly caused by the Error task halting the build. I'd prefer that the other errors don't show up at all, but failing that, the Error task error should at least be on the top of the list and certainly not a mere warning. How can I fix this?
The Error task looks like this:
<Target Name="ShowError">
<Error Text="ToErrIsHuman" Code="CS0518"/>
</Target>
The Project has InitialTargets="ShowError" to trigger the Error task. The Code attribute does not seem to have any effect.
Error shows up in 4.x .NET Framework projects. Restart Visual Studio to fix.

MSB4018 The "RazorGenerate" task failed unexpectedly

I have updated my visual studio 2019 to latest version with .net 5
after that any project with .net core 2.2 gives this error
Error MSB4018 The "RazorGenerate" task failed unexpectedly.
System.InvalidOperationException: DOTNET_HOST_PATH is not set
at Microsoft.AspNetCore.Razor.Tasks.DotNetToolTask.get_DotNetPath()
After one day try to run the project i find out
that you have to install from huget
PackageReference Include="Microsoft.NET.Sdk.Razor" Version="2.2.0"
to solve the problem
After one day try to run the project i find out that you have to install from nuget PackageReference Include="Microsoft.NET.Sdk.Razor" Version="2.2.0" to solve the problem
This is something issue with VS. for me I have added 'DOTNET_HOST_PATH' path with
%ProgramFiles%\dotnet\dotnet.exe . and restarted . problem solevd

The "TransformWebConfig" task failed unexpectedly - System.Exception: The acceptable value for AspNetCoreModuleHostingModel property is either

I get
'The "TransformWebConfig" task failed unexpectedly. System.Exception: The acceptable value for AspNetCoreModuleHostingModel property is either "InProcess" or "OutOfProcess".'
error while publishing an ASP.NET Core 2.2.0 application (actually it is the included sample application) for win-x64 environment. Both Visual Studio 2017 and 2019 gives the same error. I am working on Windows 10. What should I do to solve this?
Last part of publish Output is:
c:\users\engin\source\repos\NetCoreWebApplication2\NetCoreWebApplication2\obj\Release\netcoreapp2.2\win-x64\PubTmp\Out\
C:\Program Files\dotnet\sdk\2.2.200-preview-009648\Sdks\Microsoft.NET.Sdk.Publish\build\netstandard1.0\TransformTargets\Microsoft.NET.Sdk.Publish.TransformFiles.targets(49,5): Hata MSB4018: "TransformWebConfig" görevi beklenmedik biçimde başarısız oldu.
System.Exception: The acceptable value for AspNetCoreModuleHostingModel
property is either "InProcess" or "OutOfProcess".
konum: Microsoft.NET.Sdk.Publish.Tasks.WebConfigTransform.TransformAspNetCore(XElement aspNetCoreElement, String appName, Boolean configureForAzure, Boolean useAppHost, String extension, String aspNetCoreModuleName, String aspNetCoreHostingModel)
konum: Microsoft.NET.Sdk.Publish.Tasks.WebConfigTransform.Transform(XDocument webConfig, String appName, Boolean configureForAzure, Boolean useAppHost, String extension, String aspNetCoreModuleName, String aspNetCoreHostingModel, String environmentName)
konum: Microsoft.NET.Sdk.Publish.Tasks.TransformWebConfig.Execute()
konum: Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
konum: Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()
2 Derleme başarısız oldu. Daha fazla ayrıntı için çıktı penceresini denetleyin.
========== Oluşturma: 1 başarılı, 0 başarısız, 0 güncel, 0 atlandı ==========
========== Yayın: 0 başarılı, 1 başarısız, 0 atlandı ==========
I would suggest disabling web.config transforms altogether. In an ASP.Net Core project you probably do not need to transform web.configs since supplying environment variables is handled by convention with appsettings.[Environment].json files.
From the docs at https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/?view=aspnetcore-2.2:
To prevent the Web SDK from transforming the web.config file, use the <IsTransformWebConfigDisabled> property in the .csproj file:
<PropertyGroup>
<IsTransformWebConfigDisabled>true</IsTransformWebConfigDisabled>
</PropertyGroup>
I had the same problem and found the solution
In the csproj file, find following line and delete.
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
Had the same issue on .net core 2.2.104. Update the section to this:
<AspNetCoreHostingModelV2>InProcess</AspNetCoreHostingModelV2>
Note the V2 addition.
The answer #Barış Bar provided is working but can cause future errors. There is a bug about UpperCases. Just change InProcess in csproj file with lowercase
<AspNetCoreHostingModel>inprocess</AspNetCoreHostingModel>
It is said that the bug will be corrected in VS 2019.
InProcess or OutOfProcess
Just add this line to your web.config file
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
For me, there was a permission issue which is why, while publishing, a transformation task was running on web.config file. That file did not had access for normal user.
Closing Visual Studio and running it as Administrator then publishing the project worked for me or you can try on setting the correct permissions for the problematic file.
After successfully publishing the project once with administrator privileges, visual studio started working with normal users as well (weird though but good).
UPDATE:
Stumbled into the same problem again, and this time it was not resolved by the above solution, I had to check back the project directory and some of the files were marked Read-Only had to change it to get it working. I suppose this is a problem with the TFS which gets the files and sets them as Read-Only.
My .NET Core 2.2 application build was failing on Jenkins but it was working fine on local machine.
Error: error MSB4018: The "TransformWebConfig" task failed unexpectedly.
Fix: Removed below line from .csproj file
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
I had a project in TFS, due to some issues, the TFS went down and when I made it go online again, it failed to publish the project, while the debugging worked fine. It caused the error (The TransformWebConfig task failed unexpectedly).
After checking the output window, it seemed some files were not accessible to visual studio, or were protected. So, it was because of the TFS, all or most of the files in the project were set as Read-Only which is why Visual Studio couldn't transform those files.
Removing the Read-Only flag from the project fixed the publishing problem.
find the project file (.csproj) and update this code
<AspNetCoreHostingModel>OutProcess</AspNetCoreHostingModel>
to this
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
Adding this to the .csproj file did it for me:
<PropertyGroup>
<IsTransformWebConfigDisabled>true</IsTransformWebConfigDisabled>
</PropertyGroup>
If you are upgrading your .net core version from 3.1 to higher framework, please check web.config aspNetCore node
The attribute hostingModel should be inprocess (all small case) vs InProcess in .netcore 3.1 framework
This change worked for me and able to publish my project.

Nuget package restore - Passing in parameters to MsBuild c# API

I am looking to write a wrapper for the MSBuild C# api. I have the build all working fine, but for some odd reason I'm struggling to get Nuget package restore to run even when I pass in the parameters.
I am running this in a service that runs as NETWORK SERVICE
The command ""..\.nuget\nuget.exe" install "C:\BuildTemp\application1\packages.config" -source "" -RequireConsent -o "..\packages"" exited with code 1.
Am I passing them in correctly?
var pc = new ProjectCollection();
var buildProperties = new Dictionary<string, string>
{
{"Configuration", "Release"},
{"Platform", "Any CPU"},
{"OutputPath", _outputPath},
{"EnableNuGetPackageRestore", "true"}
};
var buildParameters = new BuildParameters(pc);
var buildRequest = new BuildRequestData("C:\myapplication.csproj",
buildProperties,
null,
new[] { "Clean", "Rebuild" },
null);
UPDATE: this appears to work in some environments and not others. Why would this be?
So I tested out this command on my local machine:
.\.nuget\NuGet.exe install Akavache\packages.config -source "" -RequireConsent -o packages
and I get an error:
Invalid URI: The format of the URI could not be determined.
which I believe is related to this bit:
-source ""
As I can drop that value and have it run again without an error.
Which begs the question, where are the package sources defined?
Inside the NuGet.targets file there's a section like this:
<ItemGroup Condition=" '$(PackageSources)' == '' ">
<!-- Package sources used to restore packages. By default, registered sources under %APPDATA%\NuGet\NuGet.Config will be used -->
<!-- The official NuGet package source (https://nuget.org/api/v2/) will be excluded if package sources are specified and it does not appear in the list -->
<!--
<PackageSource Include="https://nuget.org/api/v2/" />
<PackageSource Include="https://my-nuget-source/nuget/" />
-->
</ItemGroup>
So I propose that when you say it works "in some environments and not others" that you don't have a config file at %APPDATA%\NuGet\NuGet.Config for the service account.
Can you try changing this section in your Nuget.targets file in source control to be:
<ItemGroup Condition=" '$(PackageSources)' == '' ">
<PackageSource Include="https://nuget.org/api/v2/" />
</ItemGroup>
And see if that resolves your issues in the other environments?