I have a multiple-project solution and wish to put all the generated in/obj artifacts in a another folder.
I try to set:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugType>portable</DebugType>
<OutputPath>..\Bin\Core\Debug\</OutputPath>
<IntermediateOutputPath>..\Bin\Core\obj\</IntermediateOutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<OutputPath>..\Bin\Core\Release\</OutputPath>
<IntermediateOutputPath>..\Bin\Core\obj\</IntermediateOutputPath>
</PropertyGroup>
<ItemGroup>
<Compile Include="Library.fs" />
</ItemGroup>
</Project>
However:
The obj folder is still re-created in the original location. Is
also on the desired location but EMPTY.
The "restore packages" trigger "1" and not put them on the desired location
When the project is build, the obj folder is populated.
This is the versions:
Visual Studio Community 2017 for Mac Version 7.3.2 (build 12) Runtime:
Mono 5.4.1.7 (2017-06/e66d9abbb27) (64-bit)
NuGet Versión: 4.3.1.4445
.NET Core Runtime: /usr/local/share/dotnet/dotnet Versión de tiempo de
ejecución: 2.0.0 SDK: /usr/local/share/dotnet/sdk/2.0.0/Sdks Versión
del SDK: 2.0.0 SDK de MSBuild:
/Library/Frameworks/Mono.framework/Versions/5.4.1/lib/mono/msbuild/15.0/bin/Sdks
This problem is not specific to Visual Studio for Mac. The same behaviour occurs if you use the dotnet from the command line.
With Visual Studio for Mac, and the dotnet CLI, the obj directory gets created in the project directory on restoring the NuGet packages and contains just the files generated by the restore:
MyProject.csproj.nuget.cache
MyProject.csproj.nuget.g.targets
MyProject.csproj.nuget.g.props
project.assets.json
On building files are created in the ../Bin/Core/Debug and the ../Bin/Core/obj directories.
You can get the behaviour you want by setting the BaseIntermediateOutputPath. However setting it in the project file itself can cause problems.
The simplest solution is to create a Directory.Build.props file in the solution directory and set the BaseIntermediateOutputPath property there.
<Project>
<PropertyGroup>
<BaseIntermediateOutputPath>..\Bin\Core\obj\</BaseIntermediateOutputPath>
</PropertyGroup>
</Project>
Then the generated NuGet restore files will be created in the directory you want.
Visual Studio for Mac seems to still want to create an empty obj directory in the project when the project is opened but this has no files after the restore or build.
Related
How to set the DocumentationFile dynamically to reference the current user's home drive? Is there a $ variable to set? I checked in my project to TFS. When another member of my team clones the source code to his workstation, the following node in the .csproj still references to the folder on my hard drive, and fails the compilation. So far we have to manually edit the .csproj file. Thanks.
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DocumentationFile>C:\Users\myName\source\repos\orgName\solutionName\projectName\.xml</DocumentationFile>
</PropertyGroup>
Thanks for your reply. It leads me to find the $(MSBuildProjectDirectory) variable. Here is the PropertyGroup
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DocumentationFile>$(MSBuildProjectDirectory)\.xml</DocumentationFile>
</PropertyGroup>
There is a list of common macros in Visual Studio.
The one you probably want is $(ProjectDir)
You can also use environment variables stored in the registry. See this.
Examples:
<FinalOutput>$(BIN_PATH)\MyAssembly.dll</FinalOutput>
<Project DefaultTargets="FakeBuild">
<PropertyGroup>
<FinalOutput>$(BIN_PATH)\myassembly.dll</FinalOutput>
<ToolsPath Condition=" '$(ToolsPath)' == '' ">
C:\Tools
</ToolsPath>
</PropertyGroup>
<Target Name="FakeBuild">
<Message Text="Building $(FinalOutput) using the tools at $(ToolsPath)..."/>
</Target>
</Project>
Last last week I started having an issue with every solution I've tried to build with Visual Studio. I was using VS 2019 and our organization had just pushed down some windows updates (not sure if that's related) but after the updates I was on VS 2019 version 16.8.4, .Net version 4.8.03752.
Whenever I try to build one of our solutions (I tried 3 different solutions after doing a free pull from the main branch of our repo) I get over 1000 errors which seem to be cascade errors from the OutputPath property not being set which seems to be related to several of the projects being arbitrarily changed from Debug to Release even though the solution is set to Debug | Any CPU.
Furthermore, if I examine the build tab on the project properties (or examine them in configuration manager) NO DEBUG CONFIGURATION IS SHOWN AS AVAILABLE. If I close Visual Studio it prompts to me save changes and if I do a comparison shows that it did indeed change the configuration of several projects form Debug to Release.
I have reproduced this on 2 separate machines, with fresh installs of Visual Studio 2019 (and 2017) and pulling fresh code from the repos. Other developers in my org an build the solutions just fine and their configurations show Debug | Any CPU across the board (i.e. I seem to be the only person in the world having this problem and I'm having it on every machine I've tried and with multiple versions of Visual Studio).
I also see errors saying that projects contains nuget references that are "missing" but if I restore nuget pacakges I get a messages saying they are all installed and there is nothing to restore. I also see the "missing" packages in the packages folder.
We use relative paths for the packages so it can't be the typical literal-path issue some people have. Besides which, my folder structure hasn't changed and we all use the same folder structure in our ord.
I am completely at a loss as to what to try next. My googlefoo has completely failed me in this regard.
I'm desperately hoping someone in the Stack Exchange world can offer a solution.
Thanks,
Greg.
Please check if your project's csproj file has missed these content:
You could directly add these at the bottom of the csproj file:
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
After that, delete bin and obj folder.
Then, run update-package -reinstall under Tools-->Options-->Nuget Package Manager--> Package Manager Console to reinstall all nuget packages.
I have a MSBuild file to publish a solution (created in VS 2013 and ported to VS 2017) to a remote server. The offending line is this one:
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
When I run the command:
"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\msbuild" WebSite1_Web_configs.build /p:Configuration=Integracion;Platform="AnyCPU" /p:VisualStudioVersion=15.0
After some compilation, it ends up with this error:
Error MSB4062 The "TransformXml" task could not be loaded from the assembly C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\VisualStudio\v12.0\Web\Microsoft.Web.Publishing.Tasks.dll
Of course it can't be loaded, because the version should be 15.0, not 12.0.
Things I have tried:
Adding the /p:VisualStudioVersion=15.0 to the command where I call MSBuild. It doesn't work.
Changing, inside the *.csproj file, the element:
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
For:
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
It doesn't work.
So, how can I get the correct VS version with $(VisualStudioVersion) inside the MSBuild file without having to hardcode it?
Ok, the problem was that I had <Import> elements at the end of the *.build file. One of those imports had part of the path hardcoded:
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v12.0\WebApplications\Microsoft.WebApplication.targets" />
I changed it to:
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\WebApplications\Microsoft.WebApplication.targets" />
I executed MSBuild with the /p:VisualStudioVersion=15.0 parameter and it worked.
Please, if you have the same problem, check if you have imports with hardcoded paths.
On Visual Studio 2017, instead of edits the .csproj file, you can simple go to Visual Studio Package Manager Console (Tools -> NuGet Package Manager -> Package Manager Console) and install Web.Targets:
Install-Package MSBuild.Microsoft.VisualStudio.Web.targets
I have a Directory.Build.props file located in the same directory as the .sln file.
<Project>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DocumentationFile>bin\Debug\$(MSBuildProjectName).xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DocumentationFile>bin\Release\$(MSBuildProjectName).xml</DocumentationFile>
</PropertyGroup>
</Project>
When I build the solution using MSBuild, I am able to generate the XML files properly. However, using a Build -> Rebuild Solution task in Visual Studio doesn't generate the XML file.
Is there a difference in how Visual Studio 2017 builds and uses Directory.Build.props as opposed to MSbuild?
I had added the directory.build.props as a solution item. This somehow prevented Visual Studio from picking it up and using it in the build process. Once I removed it as a solution item, this worked fine.
You also might have to delete your .vs directory (or portion of) as it seems to be cached there as well.
https://developercommunity.visualstudio.com/content/problem/248037/defaultbuildprops-with-langversion-is-not-used-by.html
You need to check that your project file contains next row in the beginning of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
Without row Import 'magic' doesn't happen. So, you need to insert this row to all your old projects
I Have a question about msbuild integration with Visual Studio 2017 Preview.
I have a custom *.csproj:
<Project>
<Target Name="Build">
<Message Text="Hello World" Importance="High"/>
</Target>
</Project>
I want to add this project to Visual Studio, but i have an error:
Project file is incomplete. Expected imports are missing
What i need to add to my custom *.csproj to get my project working in Visual Studio?
First, I suggest you to create a project from Visual Studio or from dotnet cli, and then add your custom target to csproj file.
Anyway, I think that the minimal csproj file looks like this:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>
</Project>
This is the template from dotnet cli, of course, it depends on your project type (Console, ClassLibrary)