RestorePackages Error in NuGet.targets - nuget-package-restore

How do I resolve this error in an NuGet.targets file:
?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">$(MSBuildProjectDirectory)\..\</SolutionDir>
<!-- Enable the restore command to run before builds -->
<RestorePackages Condition=" '$(RestorePackages)' == '' ">false</RestorePackages>
Where the RestorePackages tag has an error stating that the msbuild/2003 has an invalid child element.
I get the same type of error for tags: NuGetToolsPath, PackagesProjectConfig, NuGetExePath, MsBuild, and DownloadNuGet
After these errors I get 17 cases of "unable to locate .....nuget\NuGet.exe in the 17 projects of this VS2013 solution for the MVCForum software downloaded from GitHub.

Click Build->Clean Solution and right-click the solution and set to "Enable NuGet package restore". Apparently this results in getting the correct copy of NuGet.exe. After doing this, all the errors went away.

Related

Visual Studio publish generates .pdb file despite using DebugType=None

I'm publishing a console app from within Visual Studio using the following publish profile:
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<PublishProtocol>FileSystem</PublishProtocol>
<Configuration>Release</Configuration>
<Platform>x64</Platform>
<TargetFramework>netcoreapp5.0</TargetFramework>
<PublishDir>bin\Release\netcoreapp5.0\publish\</PublishDir>
<RuntimeIdentifier>win10-x64</RuntimeIdentifier>
<SelfContained>False</SelfContained>
<PublishSingleFile>True</PublishSingleFile>
<PublishReadyToRun>True</PublishReadyToRun>
<IncludeNativeLibrariesForSelfExtract>True</IncludeNativeLibrariesForSelfExtract>
<DebugType>none</DebugType>
<DebugSymbols>false</DebugSymbols>
</PropertyGroup>
</Project>
My goal is to not emit any .pdb files (debug symbols) in the publish output folder.
This doesn't completely work as intended.
The .pdb file of the console app project is not generated - as expected, but the debug symbols for the business logic project it references is for some reason generated. Is this a bug?
I can hack this by adding a conditional statement to the project file of the business logic library, but that it something I'd like to avoid as I think all the relevant information for publishing the app should reside in the publish profile.
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DebugType>none</DebugType>
<DebugSymbols>false</DebugSymbols>
</PropertyGroup>
<DebugType>none</DebugType><DebugSymbols>false</DebugSymbols> will only prevent the generation of the current project's pdb file. And if your main project referenced a second project, these nodes will not prevent the the second project's pdb file in the main project. This is designed by that.
And if you want to prevent the referenced project's pdb file being generated into the publish folder of the main project, you should use this node additionally:
<AllowedReferenceRelatedFileExtensions>*.pdb</AllowedReferenceRelatedFileExtensions>
Solution
Add these in your pubxml file:
<DebugType>none</DebugType>
<DebugSymbols>false</DebugSymbols>
<AllowedReferenceRelatedFileExtensions>*.pdb</AllowedReferenceRelatedFileExtensions>

Get the correct $(VisualStudioVersion) for VS 2017 inside a MSBuild file

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

How to make SQL projects load version from props file?

I have created several SQL projects in visual studio, I want to manage the version of the dacpac in a centralized way. In order to fulfill that I want to reuse a props file using the answer this post :
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="$(MSBuildProjectExtension) == '.csproj'">
<CommonPlatform>$(Platform)</CommonPlatform>
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)myfile.snk</AssemblyOriginatorKeyFile>
<LinkKeyFile>$(MSBuildThisFileDirectory)myfile.snk</LinkKeyFile>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<ItemGroup Condition="$(MSBuildProjectExtension) == '.csproj'">
<Compile Include="$(MSBuildThisFileDirectory)CommonAssemblyInfo.cs">
<Link>Properties\CommonAssemblyInfo.cs</Link>
</Compile>
</ItemGroup>
<Import Project="StyleCop\StyleCop.Targets" Condition="$(MSBuildProjectExtension) == '.csproj'"/>
<!--Version management for DACPAC projects -->
<PropertyGroup Condition="$(MSBuildProjectExtension) == '.sqlproj'">
<DacVersion>15.1.0.0</DacVersion>
<DacDescription>Release 15.1</DacDescription>
</PropertyGroup>
</Project>
in the sql project I add the following import sentence:
<Import Project="..\..\Environment\MyPropsFile.props" />
If I check the properties of the project in visual studio I got this:
I build the project and unpack the dacpac file, I check the DacMetadata.xml and got this:
<?xml version="1.0" encoding="utf-8"?>
<DacType xmlns="http://schemas.microsoft.com/sqlserver/dac/Serialization/2012/02">
<Name>MyDB</Name>
<Version>1.0.0.0</Version>
</DacType>
If I build the MSBuild for the sql project and unpack the dacpac file, I check the DacMetadata.xml and got this:
<?xml version="1.0" encoding="utf-8"?>
<DacType xmlns="http://schemas.microsoft.com/sqlserver/dac/Serialization/2012/02">
<Name>MyDB</Name>
<Version>15.1.0.0</Version>
<Description>Release 15.1</Description>
</DacType>
What should I do to see the changes in the version and description from Visual Studio?
This approach can work in Visual Studio, but the DAC version metadata is unfortunately cached when the solution is loaded. This means that if you want the metadata to be reloaded from the props file, you must close and re-open the entire solution. (Unloading and reloading the database project isn't sufficient).

Visual Studio Publish Profile Publishes Wrong Build Configuration

I'm trying to automate deploying a Web Api 2 project with Visual Studio 2013. I've made a publish profile named "Test" shown below
<?xml version="1.0" encoding="utf-8"?>
<!--
This file is used by the publish/package process of your Web project. You can customize the behavior of this process
by editing this MSBuild file. In order to learn more about this please visit http://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>FileSystem</WebPublishMethod>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>x86</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish />
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<ExcludeApp_Data>False</ExcludeApp_Data>
<publishUrl>C:\DbServiceDeploy</publishUrl>
<DeleteExistingFiles>True</DeleteExistingFiles>
</PropertyGroup>
</Project>
Even though it has the line <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration> it seems like Visual Studio is publishing my debug build. I'm calling msbuild like so
"C:\Program Files (x86)\MSBuild\12.0\Bin\MSBuild.exe" C:\somefolder\Myproj.csproj /p:
DeployOnBuild=true /p:PublishProfile=Test
This excellent blog post led me to find the answer http://sedodream.com/2012/10/27/MSBuildHowToSetTheConfigurationProperty.aspx . I'll summarize in case the link dies: when a build is kicked off MsBuild evaluates the properties once and uses that value for the remainder of the build. Since the Configuration property was resolving to Debug MsBuild was using that as the Configuration to publish.
TLDR;
Pass the configuration on the command line, add
/p:Configuration=Release
to the command line call

ExcludeFilesFromDeployment not working in Visual Studio 2013 Publish Web

I have a fairly straightforward MVC 5 project in Visual Studio 2013. I have successfully set up publishing via Web Deploy to the server. I want to exclude a certain file from deployment without having to preview/uncheck it every time I publish (I am publishing the Release build).
I have edited the .csproj file for the project to include the <ExcludeFilesFromDeployment> tag.
<Project...>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
...
<ExcludeFilesFromDeployment>Library-that-is-not-good-for-server.dll</ExcludeFilesFromDeployment>
</PropertyGroup>
But nothing changes/the file still needs to be unchecked for addition when I go to publish in VS2013.
I have also tried adding a bin\ in front of the library, just in case. Not to mention, a warning pops up for the element that says "The element 'PropertyGroup' in namespace 'http://schemas.microsoft.com/developer/msbuild/2003' has invalid child element 'ExcludeFilesFromDeployment' in namespace 'http://schemas.microsoft.com/developer/msbuild/2003'. ..."
Microsoft's documentation that I was able to find in searches regarding excluding files from deployment, and the ExcludeFilesFromDeployment tag, http://msdn.microsoft.com/en-us/library/ee942158(v=vs.110).aspx, claim that the instructions only apply to VS2012 and partially to VS2010. Does anyone know what has changed for VS2013 or what I am doing wrong?
You need to add it in the profileName.pubxml file.
profileName.pubxml file position is:
my project ----> Properties ----> PublishProfiles ---> profileName.pubxml
Example:
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ExcludeFilesFromDeployment>
Library-that-is-not-good-for-server.dll
</ExcludeFilesFromDeployment>
''' ''''
You probably need to have the following definition also in the 'profileName'.pubxml file:
<DeleteExistingFiles>False</DeleteExistingFiles>
Please remove all files from your Temp publish location(normally obj\Release\Package\PackageTmp) after excluding some files or directories.

Resources