Avatar of Don VonderBurg
Don VonderBurg
Flag for United States of America asked on

VS 2013 the command copy exited with code 1

I've converted a rather large VB.Net project to C# in Visual Studio 2013. The only error left is in my macro in my post build. The post-build command line is:

copy "$(ProjectDir)MSI\ReadMe.rtf" "$(TargetDir)"
copy "$(ProjectDir)MSI\rtfEULA.rtf" "$(TargetDir)"

I get the error:

Error      1      The command "copy "MSI\ReadMe.rtf" ""
copy "MSI\rtfEULA.rtf" """ exited with code 1.      PMTools

If you notice the $(ProjectDir) and the $(TargetDir) appear to be missing the variables. I have opened up the edit post-build and clicked on the Macro... button to list the available macros values. Both macros have the proper value in them. So somewhere they are going blank during the build of the project?
C#.NET ProgrammingVisual Basic.NET

Avatar of undefined
Last Comment
Don VonderBurg

8/22/2022 - Mon
Craig Yellick

Sounds like the build process is getting confused and not initializing the variables. Create a new solution and try the macros there -- no doubt they'll work just fine. It's something about your specific solution.

Here's a thread I found about the problem. No definitive solution, unfortunately.
http://stackoverflow.com/questions/985900/tfs-msbuild-projectdir-blank-or-random

Is the solution under version control? In the above thread one guy wrote:

I branched an existing project and $(ProjectDir) kept the old directory in the newly branched code. But that's because I had some compiling errors. Once every project in the solution compiled without errors, $(ProjectDir) changed to the correct path.

Not exactly your problem but might point toward a configuration error somewhere in the background.

-- Craig
Don VonderBurg

ASKER
Craig - you're correct that a newly created solution will perform the action in the post-build. I am still researching and have yet to find a solution. I am following links in your lead.
sarabande

$(TargetDir) will get the setting from the entry to 'Output Directory' in the Configuration-General page.

while 'Output Directory' is a relative path (relative to Project Directory) the $(TargetDir) was translated as an absolute path. note, you may get a build warning if the output directory doesn't end with a back-slash.

in the post-build event page you can check the current values for the macros by clicking into the edit line, then open the drop-down and choose 'Edit...'. in the following dialog page, there is a button 'Macros>>' where you can see the current Setting of all internal and external variables. note, that the current configuration you have chosen will change the results.

Sara
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Don VonderBurg

ASKER
Sara - the issue is the $(TargetDir) in the macro list show the proper path as absolute but during compile the path becomes blank. The error results shows "" for the replacement of the $(TargetDir). So somewhere during the compile process it appears that Visual Studio is losing the content of the macro variables.
sarabande

do you get this with 'debug' and 'release' configuration?

or are you using  a non-standard configuration?

the variables are permanently set and only change when you select a different project or configuration.

try to use $(ProjectDir)$(Configuration) instead of $(TargetDir). this should be equivalent  if for ever reason vs changed either project or configuration in the post build step, you should get a hint.

if the same error occurs, i would suggest to create a new project from scratch and copy the source files to the new project folder(s). then add the source files to the project as 'existing items'. in the properties you always should use 'all configurations' and use $(configuration) to switch between Debug and Release.

Sara
Don VonderBurg

ASKER
Sara,

I get this with either configuration. I am not using any non-standard configurations.

Don
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
sarabande

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Don VonderBurg

ASKER
Wow what an adventure. Here is what I discovered.

Any new project would run the macros properly. But the ones I copied over after a C# conversion the macro variables were all blank. When I opened my .csproj file as XML edit I found the issue.

First to open your .csproj file as XML

1. Right click the project and select unload.
2. Next right click the project file and select edit.

Look for:
 
<Import Project="$(MSBuildBinPath)/Microsoft.CSharp.targets" />

Open in new window

(It will be near the bottom of the file)

This section needs to be just below the close item group:
</ItemGroup>

Open in new window


Mine was relocated after the Project Extensions.

 </ItemGroup>
  <ProjectExtensions>
    <VisualStudio>
      <UserProperties BuildVersion_UpdateAssemblyVersion="True" BuildVersion_UpdateFileVersion="True" BuildVersion_ConfigurationName="Release" BuildVersion_BuildAction="Build" BuildVersion_BuildVersioningStyle="None.None.Increment.None" BuildVersion_StartDate="2014/8/18" />
    </VisualStudio>
  </ProjectExtensions>
  <PropertyGroup>
    <PostBuildEvent>
    </PostBuildEvent>
  </PropertyGroup>
  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
       Other similar extension points exist, see Microsoft.Common.targets.
  <Target Name="BeforeBuild">
  </Target>
  <Target Name="AfterBuild">
  </Target>
  -->
  <Import Project="$(MSBuildBinPath)/Microsoft.CSharp.targets" />
</Project>

Open in new window


After I changed it to be:

<ItemGroup>
    <None Include="Resources\sidebarpmtools.jpg" />
  </ItemGroup>
  <Import Project="$(MSBuildBinPath)/Microsoft.CSharp.targets" />
  <ProjectExtensions>
    <VisualStudio>
      <UserProperties BuildVersion_UpdateAssemblyVersion="True" BuildVersion_UpdateFileVersion="True" BuildVersion_ConfigurationName="Release" BuildVersion_BuildAction="Build" BuildVersion_BuildVersioningStyle="None.None.Increment.None" BuildVersion_StartDate="2014/8/18" />
    </VisualStudio>
  </ProjectExtensions>
  <PropertyGroup>
    <PostBuildEvent>
    </PostBuildEvent>
  </PropertyGroup>
  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
       Other similar extension points exist, see Microsoft.Common.targets.
  <Target Name="BeforeBuild">
  </Target>
  <Target Name="AfterBuild">
  </Target>
  -->
</Project>

Open in new window


Everything works. Thank you Sara for leading me in the right directions. What I did is compare the XML of a working project with mine.